rin67630
Posts: 202
Joined: Fri Mar 04, 2016 10:15 am

Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Sun Mar 10, 2019 3:22 am

Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Hi experts here,
I am in the process of interfacing an Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX (/dev/ttyAMA0).
The Pro Mini should also be reprogrammable using the Arduino-IDE.
That currently works well.

But "in fine" the whole hardware will be remote and I will control everything using VNC.
The problem is that to program the Pro Mini, one must push reset at the right time. If everything is remote, I won't be there to do that.

So I searched for DTR Autoreset and found that solution.
https://github.com/deanmao/avrdude-rpi

It looks quite straightforward, but I have got a bench of showstoppers:

Code: Select all

wget https://raw.github.com/deanmao/avrdude-rpi/master/autoreset
wget https://raw.github.com/deanmao/avrdude-rpi/master/avrdude-autoreset
sudo cp autoreset /usr/bin
sudo cp avrdude-autoreset /usr/bin
sudo mv /usr/bin/avrdude /usr/bin/avrdude-original
sudo ln -s /usr/bin/avrdude-autoreset /usr/bin/avrdude
sudo chmod 755 /usr/bin/avrdude-autoreset
sudo chmod 755 /usr/bin/autoreset

It begins with "sudo mv /usr/bin/avrdude /usr/bin/avrdude-original"

The 1st problem is that the current Arduino IDE is installed at /home/pi/arduino-1.8.8 and averdude exists only at /home/pi/arduino-1.8.8/hardware/tools/avr/bin.

Si I made a first attempt to replacing "/usr/bin" with /home/pi/arduino-1.8.8/hardware/tools/avr/bin in all instuctions
I had to make the path replacement in avrdude-autoreset as well.

Upon attemting to upload my sketch I got

Code: Select all

sh: 1: autoreset: Permission denied
strace: |autoreset: Broken pipe

avrdude-original: Version 6.3-20171130
                  Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
                  Copyright (c) 2007-2014 Joerg Wunsch

                  System wide configuration file is "/home/pi/arduino-1.8.8/hardware/tools/avr/etc/avrdude.conf"
strace: |autoreset: Broken pipe
strace: |autoreset: Broken pipe
                  User configuration file is "/home/pi/.avrduderc"
                  User configuration file does not exist or is not a regular file, skipping

strace: |autoreset: Broken pipe
                  Using Port                    : /dev/ttyAMA0
                  Using Programmer              : arduino
                  Overriding Baud Rate          : 57600
strace: |autoreset: Broken pipe
	[i][error 7 times repeated][/i]
strace: |autoreset: Broken pipe
avrdude-original: stk500_getsync() attempt 1 of 10: not in sync: resp=0xe0
	[i][error 8 times repeated][/i]
avrdude-original: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe0

avrdude-original done.  Thank you.

strace: |autoreset: Broken pipe
I did read that the Arduino IDE should be invoked with sudo in order to get the rights to change the GPIO states
so it invoked it with
~/arduino-1.8.8 $ sudo bash arduino

But then it did not compile any more arguing that libraries were missing.
I had to replace the #include "library" statments with quotes with #include <library> statements with brackets.

Then I could compile, but still got the "permission denied" and "broken pipe" errors:

Code: Select all

sh: 1: autoreset: Permission denied
strace: |autoreset: Broken pipe
	[i]Error repeated 10 times[/i]
strace: |autoreset: Broken pipe
avrdude-original: stk500_getsync() attempt 1 of 10: not in sync: resp=0xe0
	[i]Error repeated 10 times[/i]
avrdude-original: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe0

strace: |autoreset: Broken pipe
An error occurred while uploading the sketch
Now i got cueless...

Any advice is highly appreciated.
Regards
Laszlo

rin67630
Posts: 202
Joined: Fri Mar 04, 2016 10:15 am

Solved: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Sun Mar 10, 2019 11:19 am

since i haven't got any advice it tried it the other way around and left all the code under /usr/bin, making a symlink to the original place at /home/pi/arduino-1.8.8/hardware/tools/avr/bin/:

Code: Select all

wget https://raw.github.com/deanmao/avrdude-rpi/master/autoreset
wget https://raw.github.com/deanmao/avrdude-rpi/master/avrdude-autoreset
sudo cp autoreset /usr/bin
sudo cp avrdude-autoreset /usr/bin
sudo mv /home/pi/arduino-1.8.8/hardware/tools/avr/bin/avrdude /usr/bin/avrdude-original
sudo ln -s /usr/bin/avrdude-autoreset /home/pi/arduino-1.8.8/hardware/tools/avr/bin/avrdude
sudo chmod 755 /usr/bin/avrdude-autoreset
sudo chmod 755 /usr/bin/autoreset
Apparently it was successful:

Code: Select all

avrdude-original: Version 6.3-20171130
                  Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
                  Copyright (c) 2007-2014 Joerg Wunsch

                  System wide configuration file is "/home/pi/arduino-1.8.8/hardware/tools/avr/etc/avrdude.conf"
                  User configuration file is "/root/.avrduderc"
                  User configuration file does not exist or is not a regular file, skipping

                  Using Port                    : /dev/ttyAMA0
                  Using Programmer              : arduino
                  Overriding Baud Rate          : 57600
done with autoreset
strace: |autoreset: Broken pipe
strace: |autoreset: Broken pipe
                  AVR Part                      : ATmega328P
                  Chip Erase delay              : 9000 us
                  PAGEL                         : PD7
                  BS2                           : PC2
                  RESET disposition             : dedicated
                  RETRY pulse                   : SCK
                  serial program mode           : yes
                  parallel program mode         : yes
                  Timeout                       : 200
                  StabDelay                     : 100
                  CmdexeDelay                   : 25
                  SyncLoops                     : 32
                  ByteDelay                     : 0
                  PollIndex                     : 3
                  PollValue                     : 0x53
                  Memory Detail                 :

                                           Block Poll               Page                       Polled
                    Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
                    ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
                    eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
                    flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
                    lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                    hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                    efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                    lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                    calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

                  Programmer Type : Arduino
                  Description     : Arduino
                  Hardware Version: 2
                  Firmware Version: 1.16
                  Vtarget         : 0.0 V
                  Varef           : 0.0 V
                  Oscillator      : Off
                  SCK period      : 0.1 us

avrdude-original: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude-original: Device signature = 0x1e950f (probably m328p)
avrdude-original: reading input file "/tmp/arduino_build_713328/Arduino_DFLD_Redesign_2018.ino.hex"
avrdude-original: writing flash (9608 bytes):

Writing | ################################################## | 100% 2.68s

avrdude-original: 9608 bytes of flash written
avrdude-original: verifying flash memory against /tmp/arduino_build_713328/Arduino_DFLD_Redesign_2018.ino.hex:
avrdude-original: load data flash data from input file /tmp/arduino_build_713328/Arduino_DFLD_Redesign_2018.ino.hex:
avrdude-original: input file /tmp/arduino_build_713328/Arduino_DFLD_Redesign_2018.ino.hex contains 9608 bytes
avrdude-original: reading on-chip flash data:

Reading | ################################################## | 100% 2.04s

avrdude-original: verifying ...
avrdude-original: 9608 bytes of flash verified
strace: |autoreset: Broken pipe
strace: |autoreset: Broken pipe
strace: |autoreset: Broken pipe
strace: |autoreset: Broken pipe
strace: |autoreset: Broken pipe

avrdude-original done.  Thank you.

strace: |autoreset: Broken pipe
Albeit I got a bench of "broken pipe" errors, it has nevertheless uploaded the sketch...

User avatar
scruss
Posts: 2186
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Sun Mar 10, 2019 1:40 pm

The github package assumes you have avrdude installed in /usr/bin. You can do this with sudo apt install avrdude.

You'll also need python-rpi.gpio installed for this script to work.

Since avrdude-rpi hasn't seen any updates since the very early days of Raspberry Pi (and the author hasn't responded to issues since 2013) it may no longer be useful.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

rin67630
Posts: 202
Joined: Fri Mar 04, 2016 10:15 am

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Sun Mar 10, 2019 2:20 pm

scruss wrote:
Sun Mar 10, 2019 1:40 pm
The github package assumes you have avrdude installed in /usr/bin. You can do this with sudo apt install avrdude.
Yes, but the current Arduino IDE 1.8.8 uses avrdude at another location. The two posts will explain how to cope with the discrepancy.
scruss wrote:
Sun Mar 10, 2019 1:40 pm
Since avrdude-rpi hasn't seen any updates since the very early days of Raspberry Pi (and the author hasn't responded to issues since 2013) it may no longer be useful.
Maybe, but we haven't got anything better, have we?

User avatar
scruss
Posts: 2186
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Sun Mar 10, 2019 5:18 pm

avrdude is pretty much avrdude. Since what you're trying to do was written in 2012, the Raspbian avrdude will put itself in the right place and have config files in regular places too. The Arduino version will have all of its configuration files set up locally to its installation folder, and you don't want to break those by installing this DTR patch on top of them.

There may not be anything better, but the chances of this working in 2019 based on how shaky Raspberry Pi GPIO was in 2012 is slim.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

PhatFil
Posts: 1098
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Sun Mar 10, 2019 5:51 pm

forgive me if i am missing something here but looking at the op's solution link the 'business' is just

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)
Not something you need an outdated framework to implement perhaps?

User avatar
HawaiianPi
Posts: 3748
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Mon Mar 11, 2019 12:44 am

An easier solution might be to use a USB-TTL adapter with a DTR line. I've programmed breadboard 'duinos and Pro Minis with cheap CP2102 adapters that can be found on eBay for less than $2 (a bit more if you want faster shipping). The 6 pin models usually have DTR (but double-check that, as they're not all the same). Linux has native support for the CP2102, so it should work in Raspbian.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

rin67630
Posts: 202
Joined: Fri Mar 04, 2016 10:15 am

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Mon Mar 11, 2019 8:35 am

HawaiianPi wrote:
Mon Mar 11, 2019 12:44 am
An easier solution might be to use a USB-TTL adapter with a DTR line.
That is precisely what I do NOT want to do.
The USB-TTL adapter and the whole USB frills are way too bulky and unconvenient.
Connecting a 3,3V Arduino to a 3,3V GPIO is the natural way of interconnecting two devices.
You can put the Pro Mini on a 7x3cm pcb as a hat for the Raspberry Pi with NO cables at all.

I have lodged a RaspberryPi Zero, an Arduino, some other minor components and the 220V Power supply in a small cabinet that measures only 8x5,5x3,5cm.

rin67630
Posts: 202
Joined: Fri Mar 04, 2016 10:15 am

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Mon Mar 11, 2019 8:40 am

PhatFil wrote:
Sun Mar 10, 2019 5:51 pm
forgive me if i am missing something here but looking at the op's solution link the 'business' is just

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)
Not something you need an outdated framework to implement perhaps?
You are right, that is exactly what the solution does.
The only tiny detail is to manage it at the right moment: i.e. exactly when avrdude is triggered from the arduino IDE.

rin67630
Posts: 202
Joined: Fri Mar 04, 2016 10:15 am

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Mon Mar 11, 2019 8:42 am

scruss wrote:
Sun Mar 10, 2019 5:18 pm
There may not be anything better, but the chances of this working in 2019 based on how shaky Raspberry Pi GPIO was in 2012 is slim.
Hmm... It actually works.
:D

User avatar
scruss
Posts: 2186
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Mon Mar 11, 2019 10:09 pm

rin67630 wrote:
Mon Mar 11, 2019 8:35 am
The USB-TTL adapter and the whole USB frills are way too bulky and inconvenient.
There's always the ICSP connector. It's a decent way to program the Arduino, and can be bit-banged via GPIO. I think avrdude even has a setting for that
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

rin67630
Posts: 202
Joined: Fri Mar 04, 2016 10:15 am

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Tue Mar 12, 2019 3:18 pm

scruss wrote:
Mon Mar 11, 2019 10:09 pm
There's always the ICSP connector.
Really? on a Pro Mini?
:o

User avatar
scruss
Posts: 2186
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Tue Mar 12, 2019 11:14 pm

Yup, the SPI pins + power + reset.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

rin67630
Posts: 202
Joined: Fri Mar 04, 2016 10:15 am

Re: Arduino Pro Mini 8MHz 3,3V with a Raspberry Pi over GPIO RX-TX and autoreset...

Tue Mar 12, 2019 11:52 pm

scruss wrote:
Tue Mar 12, 2019 11:14 pm
Yup, the SPI pins + power + reset.
SPI is already used.

Return to “Troubleshooting”