Pi GPIO in place of USB-UART

Need help? Ask here and someone will help
chuchuchuchu
Posts: 12
Joined: Mon Dec 19, 2016 5:04 pm

Re: Pi GPIO in place of USB-UART

Post by chuchuchuchu »

joe wrote:I am using it with the onboard UART since a long time and had the same problem. Power the Pi from Ps4 with a switched of PS4 (not standby). Then wait until G25 started its initialisation procedure turning full right - plug the arduino into the second PS4 Port powering it while wheel is on its way to full left. With this timing its working in 99%. I think there is some trash on uart signal of pi so the arduino thinks it should start sending its "presence" when raspberry is not listening. Later raspberry is listening but arduino is no longer telling it is there. it would by nice if gimx would give us a reset for the arduino on GPiO and then wait for it. Maybe a bigger capacitor keeping the arduino longer in reset and powering both devices same time will also work.
(still using wheezy on Raspberry B).
Same behavior here. Pro micro needs to start after rpi. I am thinking on an additional button to reset pro micro connecting RST - GND, but a software solution (Avoiding handshake or assuming ok the same) or an automatic solution (resetting arduino from rpi before gimx starts for example) would be better :)
I don't know if at firmware level could exist a solution for that. (Resending whatever signal periodically or adding a delay on startup allowing rpi gpio bring up properly)
User avatar
Matlo
Posts: 5768
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Pi GPIO in place of USB-UART

Post by Matlo »

I'll try to make the adapter tolerant to garbage from GIMX 7.
https://github.com/matlo/GIMX/issues/426
GIMX creator
chuchuchuchu
Posts: 12
Joined: Mon Dec 19, 2016 5:04 pm

Re: Pi GPIO in place of USB-UART

Post by chuchuchuchu »

Matlo wrote:I'll try to make the adapter tolerant to garbage from GIMX 7.
https://github.com/matlo/GIMX/issues/426
Thanks Matlo ;) I will follow the #426 issue progress.
Meanwhile, any idea about how to reset adapter manually at O.S. level? (Isolated command scheduled every minute on a cron task should be work sooner or later)

Happy new year!
User avatar
Matlo
Posts: 5768
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Pi GPIO in place of USB-UART

Post by Matlo »

Wire a GPIO of the RPi to the RST pin of the atmega32u4. Pull it low to trigger a reset.
The below code configures pin 24 as an output, and pulls it low for 1 second.

Code: Select all

echo 24 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio24/direction
echo 1 > /sys/class/gpio/gpio24/value
sleep 1
echo 0 > /sys/class/gpio/gpio24/value
sleep 1
echo 1 > /sys/class/gpio/gpio24/value
This is untested and it may not work as the logic level is 3.3V on the RPi vs 5V on the atmega32u4 board.
Let me know if this works, and the adjustments if required.
GIMX creator
chuchuchuchu
Posts: 12
Joined: Mon Dec 19, 2016 5:04 pm

Re: Pi GPIO in place of USB-UART

Post by chuchuchuchu »

Thanks Matlo. I will try it as soon i can ;)

At first look, I am not sure if it will be safe leaving the atmega32u4 RST pin at 3.3V continuously.
I have checked also how to programme an AVR from RPi using avrdude and a DTR pin is emulated, setting the RPi pin HIGH only for 0.12 seconds instead of setting the RPi LOW and leaving the pin HIGH, but i don't know how to adapt it to our use case :oops: Maybe that is a better approach.
https://github.com/deanmao/avrdude-rpi

Code: Select all

def reset():
  pin = 11
  GPIO.setup(pin, GPIO.OUT)
  GPIO.output(pin, GPIO.HIGH)
  time.sleep(0.12)
GPIO.output(pin, GPIO.LOW)
User avatar
Matlo
Posts: 5768
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Pi GPIO in place of USB-UART

Post by Matlo »

Page 7: http://www.atmel.com/Images/Atmel-7766- ... asheet.pdf
Reset input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running. The minimum pulse length is given in Table 8-2 on page 53. Shorter pulses are not guaranteed to generate a reset.
GIMX creator
chuchuchuchu
Posts: 12
Joined: Mon Dec 19, 2016 5:04 pm

Re: Pi GPIO in place of USB-UART

Post by chuchuchuchu »

Good news. Workaround is working as expected ;)

Steps needed:

Physically
RPi's PIN40 / GPIO21 connected to ATmega32u4 RST pin directly.
Logically
[*]New bash script created /home/pi/resetArduino.sh with content shown below:

Code: Select all

#!/bin/bash

echo 21 > /sys/class/gpio/export
sleep 1
echo out > /sys/class/gpio/gpio21/direction
sleep 1
echo 1 > /sys/class/gpio/gpio21/value
sleep 1
echo 0 > /sys/class/gpio/gpio21/value
sleep 1
echo 1 > /sys/class/gpio/gpio21/value

exit 0
[*]Grant execution permissions

Code: Select all

chmod +x /home/pi/resetArduino.sh
[*]Add the new script to boot sequence (like we do with blink.py program)

Code: Select all

pi@raspberrypi:~ $ crontab -l
@reboot /home/pi/resetArduino.sh && python /home/pi/blink.py &
Using this configuration, GIMX is able to start correctly on its first attempt when RPi and ATmega32u4 are powered on from PS4 simultaneously using GPIO instead of CP2102 USB UART.
User avatar
Matlo
Posts: 5768
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Pi GPIO in place of USB-UART

Post by Matlo »

Good to know. It would be nice if you could add this on the RPi wiki page, with a short explanation on why this is necessary.
GIMX creator
chuchuchuchu
Posts: 12
Joined: Mon Dec 19, 2016 5:04 pm

Re: Pi GPIO in place of USB-UART

Post by chuchuchuchu »

Wiki updated. Feel free to correct/add/remove any point ;)
User avatar
Matlo
Posts: 5768
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Pi GPIO in place of USB-UART

Post by Matlo »

Thanks!
GIMX creator
Post Reply