Jump to content


Photo

Problem with analogRead


  • Please log in to reply
9 replies to this topic

#1 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 03 December 2014 - 02:11 AM

Hi, i 'm being made a little program to test the GPIO on my pcduino (under android). For this i use cross-compiling with Qt5 under linux. At first time i would just power on/off a led with 2 pushbutton, it's woks fine with pin 2 (but if i put the 3 output, it don't works !). See some pictures under :

my board test configuration (i use i cubloc protoboard that i already have for the test, it's more fast to connect potantiometer ...)
p1150110.jpg

The application on android (sorry it,s in french). In top, 2 pushbutton for power on/off the led, under a label (for previous test) and in bottom a quit pushbutton.

p1150111.jpg

The result ;

p1150112.jpg

after that i woul to read a potentiometer value on adc pin but my application crash and i don't know why ! under the code i use in Qt :

 

 

main.cpp :

#include <QApplication>
#include "fenetre.h"

int main(int argc, char *argv[])
{

    QApplication a(argc, argv);
    Fenetre aplli;
    aplli.show();
    
    return a.exec();
}

fenetre.h :

#ifndef FENETRE_H
#define FENETRE_H

#include <QWidget>
#include <QPushButton>
#include <Arduino.h>
#include <QLayout>
#include <QLabel>

class Fenetre : public QWidget
{
    Q_OBJECT
public:
    explicit Fenetre(QWidget *parent = 0);
    
signals:
    
public slots:
    void ledOn();
    void ledOff();

private :
    QPushButton allumerLed,eteindreLed,quitter;
    QLabel *potentiometre;
    int led_pin,potar_pin, valPotar;
};

#endif // FENETRE_H


fenetre.cpp :

#include "fenetre.h"

Fenetre::Fenetre(QWidget *parent) :
    QWidget(parent),led_pin(2),potar_pin(A5)
{

        setFixedSize(500,500);
        allumerLed.setText("allumer led"); //text in english : "power on led"
        eteindreLed.setText("Eteindre led"); //text in english : "power off led"
        quitter.setText("Quitter"); //text in english : "exit"
        potentiometre=new QLabel("Valeur du potentiomètre :");//text in english : "potentiometer value "
        QVBoxLayout *layoutPrincipal = new QVBoxLayout;
        QHBoxLayout *layoutVertical = new QHBoxLayout;
        QVBoxLayout *layoutVertical2 = new QVBoxLayout;
        layoutVertical->addWidget(&allumerLed);
        layoutVertical->addWidget(&eteindreLed);
        layoutVertical2->addWidget(potentiometre);
        layoutPrincipal->addLayout(layoutVertical);
        layoutPrincipal->addLayout(layoutVertical2);
        layoutPrincipal->addWidget(&quitter);
        setLayout(layoutPrincipal);

        init();
        pinMode(led_pin, OUTPUT);
        digitalWrite(led_pin,HIGH);
        valPotar=analogRead(potar_pin);


        connect(&quitter,SIGNAL(clicked()),this,SLOT(close()));
        connect(&allumerLed,SIGNAL(clicked()),this,SLOT(ledOn()));
        connect(&eteindreLed,SIGNAL(clicked()),this,SLOT(ledOff()));

}

void Fenetre::ledOn()
{
    digitalWrite(led_pin, LOW);
}

void Fenetre::ledOff()
{
    digitalWrite(led_pin, HIGH);
}

During the compilation (with and without analogRead) this warning in Qt creator :

In file included from ../../../Java/android-ndk-r8e/platforms/android-14/arch-arm/usr/include/sys/ioctl.h:34:0,
                 from ../../../c_android/install/include/Arduino.h:12,
                 from ../test/fenetre.h:6,
                 from ../test/main.cpp:2:
../../../Java/android-ndk-r8e/platforms/android-14/arch-arm/usr/include/asm/termbits.h:96:0: warning: "B0" redefined [enabled by default]
../../../c_android/install/include/binary.h:4:0: note: this is the location of the previous definition
../../../Java/android-ndk-r8e/platforms/android-14/arch-arm/usr/include/asm/termbits.h:99:0: warning: "B110" redefined [enabled by default]
../../../c_android/install/include/binary.h:46:0: note: this is the location of the previous definition
../../../Java/android-ndk-r8e/platforms/android-14/arch-arm/usr/include/asm/termbits.h:133:0: warning: "B1000000" redefined [enabled by default]
../../../c_android/install/include/binary.h:258:0: note: this is the location of the previous definition


Can you help me please  cry.gif ?



#2 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 03 December 2014 - 02:11 AM

Can you test it from command line:

cat /proc/adc5



#3 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 03 December 2014 - 02:11 AM

When i put this command on terminal, i obtain this :

/system/bin/sh: cat/proc/adc5 : not found



#4 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 03 December 2014 - 02:12 AM

I'm trying today to use analogWrite, but it's the same problem, it don't work ! What can i do with Android ?!!!  angry.gif



#5 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 03 December 2014 - 02:12 AM

@modjo
Can you tell me which version you use? 
The latest version is here:
http://www.pcduino.com/?page_id=14

Android Image, 03-11-2013, Note: 1. Fix the HDMI to DVI issue; 2. Fix Wifi dongle issue.

and there are also some executables which you can use to test the hardware:

root@android:/data # cd /home/android/sample/core/test/ 
root@android:/home/android/sample/test # ls
adc_test
adxl345_test
io_test
pwm_test
spi_test
uart_test
root@android:/home/android/sample/test # ./adc_test                            
Usage ./adc_test ADC_ID(0/1/2/3/4/5)
255|root@android:/home/android/sample/test # ./adc_test 0                      
read adc value on ADC0, delay is 100000 usecs
ADC0 level is 63
ADC0 level is 63
ADC0 level is 63
ADC0 level is 63
^C
130|root@android:/home/android/sample/test #


#6 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 03 December 2014 - 02:13 AM

@lds, i have the good version and i have the tools you say. When i test adc5 for exemple it works (i can read the adc value on terminal). But at the end of test i obtained this :

"open /proc/adc5 failed"

pwm_test woks also.

but when i test this program, it's crash :

#include <Arduino.h>

int led_pin = 6;

int main(void)
{

    init();
    for(;;)
    {
        analogWrite(led_pin,0);
        delay(1000);
        analogWrite(led_pin,125);
        delay(1000);
        analogWrite(led_pin,255);
        delay(1000);

    }


    return 0;
}


#7 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 03 December 2014 - 02:13 AM

Hi, Modjo,
    Thanks for your patient testing. 
Since arduino lib was updated for ubuntu kernel,  but for android, the driver is too old.

PWM driver is too old for current arduino lib,  so analogWrite crashes.
And for the issue "open /proc/adc5 failed", maybe it's caused by the permission for android.

So, We will release new android image for you and other people who want to develop on pcduino's android platform.
Please let me know if you find other bugs on android, so we can fix in the next release. smiley.gif



#8 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 03 December 2014 - 02:13 AM

Ok thanks a lot, when, you think, do you can post another release ? Another bug it's to can use elo touch screen  wink.gif



#9 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 03 December 2014 - 02:13 AM

This week will be ok.
And we will add the idc file for your touch, but without test because we have no such device.



#10 jim

jim

    Advanced Member

  • Administrators
  • 3,385 posts

Posted 03 December 2014 - 02:13 AM

Today i had installed the new android image on pcduino and for the gpio it works but not not for the elo touch (sometimes i can slide on the desk and select one icon but it's hazardous  sad.gif )






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users