XU4 with C++

Post Reply
L67GS
Posts: 45
Joined: Wed Apr 22, 2020 3:02 pm
languages_spoken: english
ODROIDs: XU4, C0, and a whole big pile of accessories, VU7A Pluss,, ect....
Has thanked: 19 times
Been thanked: 3 times
Contact:

XU4 with C++

Post by L67GS » Wed Apr 29, 2020 12:47 pm

Hello all, I'm new to Odroid, been running Linux since Redhat 6.2 back in like 1998.
I'm putting this thread up a bit early since my XU4 is still somewhere in the mail system. I have some, (obviously untested) code already and out of sheer boredom I made a spreadsheet to document the pin relationship between the XU4, Shifter, and WiringPi.
I'm also curious if anyone here has successfully used the IOs without wiringpi since there appear to be more usable GPIOs than wiringpi can use.
I'm attaching the spreadsheet if anybody is interested in it.
Attachments
OdroidMapping.ods
(18.95 KiB) Downloaded 11 times

User avatar
odroid
Site Admin
Posts: 34127
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 670 times
Been thanked: 614 times
Contact:

Re: XU4 with C++

Post by odroid » Wed Apr 29, 2020 3:14 pm

Thank you for sharing a clear and useful spreadsheet.
These users thanked the author odroid for the post:
L67GS (Wed Apr 29, 2020 3:30 pm)

User avatar
igorpec
Posts: 576
Joined: Sat Dec 12, 2015 4:34 pm
languages_spoken: english,german,slovene
ODROIDs: XU4, HC1, C2, C1+
Has thanked: 22 times
Been thanked: 74 times
Contact:

Re: XU4 with C++

Post by igorpec » Wed Apr 29, 2020 5:20 pm

Not sure if it matches XU4 (for start you need more recent kernel) but its worth checking https://github.com/sgjava/userspaceio
These users thanked the author igorpec for the post:
L67GS (Wed Apr 29, 2020 11:25 pm)
ARMBIAN
Linux for ARM development boards

Download latest images for Odroids | Build them from sources | Donate to support development

L67GS
Posts: 45
Joined: Wed Apr 22, 2020 3:02 pm
languages_spoken: english
ODROIDs: XU4, C0, and a whole big pile of accessories, VU7A Pluss,, ect....
Has thanked: 19 times
Been thanked: 3 times
Contact:

Re: XU4 with C++

Post by L67GS » Wed Apr 29, 2020 11:25 pm

Thank you odroid, I wrote a pretty simple program to test shifter IOs last night. After it's tested (and bugged out) I'll post it up so future users can hit the ground running and have sample code.
igorpec, Thank You for sharing that, it's really interesting, probably not something I would jump into before I know the hardware better but I'll have to try that later. Probably do another install on an SD card to test it.

L67GS
Posts: 45
Joined: Wed Apr 22, 2020 3:02 pm
languages_spoken: english
ODROIDs: XU4, C0, and a whole big pile of accessories, VU7A Pluss,, ect....
Has thanked: 19 times
Been thanked: 3 times
Contact:

Re: XU4 with C++

Post by L67GS » Thu Apr 30, 2020 2:58 am

I'm going to write a program to test the GPIOs as inputs, there are 2 ADC inputs, ADC#0 & ADC#3, am I correct in assuming they take 0-5V at the shifter and turn the value into a number like 0 - 1023 or something? If so, does anyone have the scale?

L67GS
Posts: 45
Joined: Wed Apr 22, 2020 3:02 pm
languages_spoken: english
ODROIDs: XU4, C0, and a whole big pile of accessories, VU7A Pluss,, ect....
Has thanked: 19 times
Been thanked: 3 times
Contact:

Re: XU4 with C++

Post by L67GS » Fri May 01, 2020 11:56 pm

Okay! I'm on it now.
So last night I downloaded wiringPi, I compiled just fine, then run the program and:
fatal error: wiringPi.h: No such file or directory
#include <wiringPi.h>

Huh? I did a gpio readall to make sure it installed and got the ascii map, no fair.

L67GS
Posts: 45
Joined: Wed Apr 22, 2020 3:02 pm
languages_spoken: english
ODROIDs: XU4, C0, and a whole big pile of accessories, VU7A Pluss,, ect....
Has thanked: 19 times
Been thanked: 3 times
Contact:

Re: XU4 with C++

Post by L67GS » Sat May 02, 2020 3:06 pm

Okay! The last couple days sucked, mostly because I'm still a very new C++ developer!
So here's the skinny, my compilation errors were because I wasn't telling the compiler the paths to the libraries. For me compilation with wiringPi on the XU4 looks like this:
g++ ProgramName.cpp -lwiringPi -lpthread -ltr -lcrypt

I wrote a little (like 400 something lines) test program and just finished testing output on all 24 GPIOs.
For the most part it went well, there's occasional glitches with wiringPi where it'll skip some if all IOs are cycled fast like at the end of the program I'm attaching.
Hopefully my input test doesn't exhibit the same trait or this will be unable to take pulse inputs and count without missing some.
It was also necessary to pull all of them low early on as the state is more or less random upon initiation, I suspect there's a way to initiate them low or high when the pins are defined in pinmode() but I've found no reference to it yet.
The code is well commented so it can be referenced easily, and the compilation string from above is in the comments as well.
Also, geany works great on the XU4! The environment that comes native is a bit minimal for my taste so having geany was a big thing for me so I could make tweaks without having to move it back and forth between computers.
Still no information on how an ADC read is used so next I'll focus on simple input then UART and PWM.
PWM can be a thing if I get past serial data, I'll simply program a PIC to do the actual work and use the XU4 as a HMI in that application.
Please remember I'm very much an amateur so please try to be critical without flames if you don't like something in the code.
OdroidGPIOToggle.cpp
(9.21 KiB) Downloaded 4 times

L67GS
Posts: 45
Joined: Wed Apr 22, 2020 3:02 pm
languages_spoken: english
ODROIDs: XU4, C0, and a whole big pile of accessories, VU7A Pluss,, ect....
Has thanked: 19 times
Been thanked: 3 times
Contact:

Re: XU4 with C++

Post by L67GS » Mon May 04, 2020 2:47 am

Here's pretty much the same program doing input testing.
I also noticed the XU4 doesn't pull random pins high at boot like I thought, it's all but 1 every time, it's pin 23 or 24.
Input is a bit odd, all the inputs are high in a relaxed state, there's no pulling them up, only down.
So if you look at my program there's no compare for high since it's a given.
The digitalread can be used the same manner as an int variable, compare it, move it to another variable and such.
Again, new programmer, crude code. If these programs were being used practically Id have to use a string variable for user input, enter a letter and it flips shit and loops out of control, it's useful to prove input works and learn wiringpi usage and that's what I was going for.
OdroidGPIOInput.cpp
(5.22 KiB) Downloaded 4 times

User avatar
odroid
Site Admin
Posts: 34127
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 670 times
Been thanked: 614 times
Contact:

Re: XU4 with C++

Post by odroid » Wed May 06, 2020 1:42 pm

L67GS wrote:
Thu Apr 30, 2020 2:58 am
I'm going to write a program to test the GPIOs as inputs, there are 2 ADC inputs, ADC#0 & ADC#3, am I correct in assuming they take 0-5V at the shifter and turn the value into a number like 0 - 1023 or something? If so, does anyone have the scale?
The ADC input voltage range is 0~1.8volt and 12bit resolution range is 0 ~ 4095.
https://wiki.odroid.com/odroid-xu4/appl ... sing_sysfs

L67GS
Posts: 45
Joined: Wed Apr 22, 2020 3:02 pm
languages_spoken: english
ODROIDs: XU4, C0, and a whole big pile of accessories, VU7A Pluss,, ect....
Has thanked: 19 times
Been thanked: 3 times
Contact:

Re: XU4 with C++

Post by L67GS » Wed May 06, 2020 11:26 pm

odroid wrote:
Wed May 06, 2020 1:42 pm
L67GS wrote:
Thu Apr 30, 2020 2:58 am
I'm going to write a program to test the GPIOs as inputs, there are 2 ADC inputs, ADC#0 & ADC#3, am I correct in assuming they take 0-5V at the shifter and turn the value into a number like 0 - 1023 or something? If so, does anyone have the scale?
The ADC input voltage range is 0~1.8volt and 12bit resolution range is 0 ~ 4095.
https://wiki.odroid.com/odroid-xu4/appl ... sing_sysfs
Thank you odroid, I can voltage divide down to 1.8, 4095 is pretty triumphant resolution!
It says in the wiki it's 1.8V @ CON10 30 pin header, I have the shifter shield, are pins 37 & 40 on the shifter still 1.8V or is it "shifted" up like the GPIO pins?
I hope it's acceptable that I'm documenting this all here, it's my hope that sharing my learning experience will help future new users to hit the ground running.

User avatar
odroid
Site Admin
Posts: 34127
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 670 times
Been thanked: 614 times
Contact:

Re: XU4 with C++

Post by odroid » Thu May 07, 2020 9:20 am

Digital IO pins can be shifted to 3.3V or 5.0V.
But the Analog input pins don't.

L67GS
Posts: 45
Joined: Wed Apr 22, 2020 3:02 pm
languages_spoken: english
ODROIDs: XU4, C0, and a whole big pile of accessories, VU7A Pluss,, ect....
Has thanked: 19 times
Been thanked: 3 times
Contact:

Re: XU4 with C++

Post by L67GS » Sat May 09, 2020 1:02 pm

Had a chance to play with analog input tonight. Hardware is: shiter, (2) 10K pots on a breadboard, sweeping between 38 (1.8V source), and 39 (Ground) to 37 (ADC0) and 40 (ADC3).

What I get is no change on adjustment to ADC0, but ADC3 works fine. ADC0 follows ADC3 to within a few percent but adjustment to ADC0 pot yields no change.
I swapped the inputs and sure enough the other pot becomes active on ADC3 so it's not a bad pot or jumper.

Is this something I'm doing incorrectly in code?
Analog.cpp
(1.07 KiB) Downloaded 5 times

User avatar
odroid
Site Admin
Posts: 34127
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 670 times
Been thanked: 614 times
Contact:

Re: XU4 with C++

Post by odroid » Mon May 11, 2020 9:24 am

Access the ADC0 and ADC3 on the command line via sysfs to narrow down root causes.
https://wiki.odroid.com/odroid-xu4/appl ... rnel_49414
These users thanked the author odroid for the post:
L67GS (Mon May 11, 2020 10:31 am)

L67GS
Posts: 45
Joined: Wed Apr 22, 2020 3:02 pm
languages_spoken: english
ODROIDs: XU4, C0, and a whole big pile of accessories, VU7A Pluss,, ect....
Has thanked: 19 times
Been thanked: 3 times
Contact:

Re: XU4 with C++

Post by L67GS » Sun May 24, 2020 10:21 am

I've been pretty quiet the couple weeks while I focus on C++, but I want to erase my marker board so I figured a picture of the voltage divider to sweep 0-5v would not only be safe here but potentially useful to others.... not that it's difficult to figure out but, hey.
20200523_211503.jpg
20200523_211503.jpg (252.26 KiB) Viewed 59 times
These users thanked the author L67GS for the post:
odroid (Mon May 25, 2020 9:49 am)

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: Google [Bot] and 1 guest