XU4 analog read

Moderators: mdrjr, odroid

XU4 analog read

Unread postby gbsutter » Fri Aug 03, 2018 7:21 am

Hi
using Python 2.7.12, OS Linux-4.14.47-132-arm7l-with-Ubuntu-16.04-xenial

I am reading 2 voltage dividers with output 0 to <1.8v verified on scope. Using AIN0 and AIN3
wpi.analogRead(n) n= 0 or 3 returns zero.
This was working correctly before
I have four XU4's all using the same MMC card for OS and having the identical issue.
Can it be an OS or wpi problem?

Thanks for any pointers, Graham
gbsutter
 
Posts: 23
Joined: Tue Jan 16, 2018 1:59 am
languages_spoken: english, french
ODROIDs: XU4

Re: XU4 analog read

Unread postby odroid » Fri Aug 03, 2018 8:53 am

Do you use our WiringPi library?
https://github.com/hardkernel/wiringPi

Can you read the analog level from the command line?
https://wiki.odroid.com/odroid-xu4/appl ... rnel_49414
User avatar
odroid
Site Admin
 
Posts: 28697
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: XU4 analog read

Unread postby gbsutter » Sat Aug 04, 2018 12:39 am

I do use the WiringPi library. The analog reads were working earlier in this project.

Hi mel_4194. Command line shows the same zero result "import wiringpi2 as wpi wpi.analogRead(0) 0" AIN3 same.

Thanks for responses.
gbsutter
 
Posts: 23
Joined: Tue Jan 16, 2018 1:59 am
languages_spoken: english, french
ODROIDs: XU4

Re: XU4 analog read

Unread postby gbsutter » Sat Aug 04, 2018 1:23 am

strike that command line report. I need to initialize pin directions as in my code.
gbsutter
 
Posts: 23
Joined: Tue Jan 16, 2018 1:59 am
languages_spoken: english, french
ODROIDs: XU4

Re: XU4 analog read

Unread postby gbsutter » Sat Aug 04, 2018 1:33 am

OK. From command line: ran wpiSetup() and set pin directions. digitalRead is good. analogRead both zero, input pins scoped ~1.8v
gbsutter
 
Posts: 23
Joined: Tue Jan 16, 2018 1:59 am
languages_spoken: english, french
ODROIDs: XU4

Re: XU4 analog read

Unread postby odroid » Sat Aug 04, 2018 9:42 am

We will check the issue early next week.
User avatar
odroid
Site Admin
 
Posts: 28697
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: XU4 analog read

Unread postby joshua.yang » Mon Aug 06, 2018 12:22 pm

gbsutter wrote:OK. From command line: ran wpiSetup() and set pin directions. digitalRead is good. analogRead both zero, input pins scoped ~1.8v


Hi, @gbsutter

I've just tested analogRead() function on WiringPi Python wrapper and would confirm that it works well.

Please refer to this code I have tested. Runs on Python 3.6.5.
Given the parameters can be 0 for WiringPi #25 and 1 for WiringPi #29.
Code: Select all
import wiringpi as wpi
import time
 
wpi.wiringPiSetup()

while True:
    print(f"{wpi.analogRead(25)} / {wpi.analogRead(29)}")
    time.sleep(1)


This code may result like,
Code: Select all
...
1675 / 1677
1673 / 1676
1675 / 1677
1677 / 1677
1673 / 1676
1671 / 1678
1679 / 1675
1674 / 1677
1673 / 1677
1674 / 1678
1673 / 1679
1677 / 1677
1673 / 1681
1679 / 1675
...


Note that I made a circuit with a variable resistor, input from 1.8V output pin(physical #38 on Shifter Shield), output to AIN3 and AIN0.

It seems you should try to download the latest WiringPi Python wrapper if you don't use that.
Please refer to this Wiki: https://wiki.odroid.com/odroid-xu4/appl ... o/wiringpi
joshua.yang
 
Posts: 89
Joined: Fri Sep 22, 2017 5:54 pm
languages_spoken: English
ODROIDs: XU4, XU4Q + Cloudshell2

Re: XU4 analog read

Unread postby gbsutter » Tue Aug 07, 2018 4:24 am

Hi Joshua - thanks for responding.

As I was previously able to read both analog pins on the XU4, I reinstalled wirngpi2 by:

git clone https://github.com/hardkernel/WiringPi2-Python.git
# cd WiringPi2-Python
# git submodule init
# git submodule update
2. Build & install
# ./build.sh

I then ran code pretty much identical to your example and (originally) found everything working. wpi.analogRead(0) and (3), the only analog pins exposed on XU4
One analog input is voltage divided 1.8v from the XU4, so quite safe. The other is a fixed voltage divided from 48v, producing max 1.6v.
Difficult to see how, but I must have damaged the ADC inputs on several units.
All digital IO used works just fine.
Graham.
gbsutter
 
Posts: 23
Joined: Tue Jan 16, 2018 1:59 am
languages_spoken: english, french
ODROIDs: XU4

Re: XU4 analog read

Unread postby odroid » Tue Aug 07, 2018 8:59 am

The logical pin numbers must be 25 & 29, not 0 & 3 as described in joshua's example code.
User avatar
odroid
Site Admin
 
Posts: 28697
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID


Return to Ubuntu

Who is online

Users browsing this forum: boardt and 1 guest

cron