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.

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

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.

So 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 attempting to upload my sketch I got:

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 statements with brackets.

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

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

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/:

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:

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...

Hi,

The original code was intended to send a DTR information on the programming connector.
I preferred to use the reset pin directly, since everyting is wired permanently.

For that I neede to reverse the reset routine in /etc/bin/ autoreset.

I changed the code to:

#!/usr/bin/python

import RPi.GPIO as GPIO
import sys, os, re, time, fcntl

fd = sys.stdin.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)

GPIO.setmode(GPIO.BOARD)
dtr = re.compile('.+TIOCM_DTR.+')
start = time.time()

def reset():
  pin = 11
  GPIO.setup(pin, GPIO.OUT)
  GPIO.output(pin, GPIO.LOW)
  time.sleep(0.32)
  GPIO.output(pin, GPIO.HIGH)
  GPIO.setup(pin, GPIO.IN)
  

def process():
  while True:
    try: 
      duration = time.time() - start
      input = sys.stdin.readline().strip()
      if dtr.match(input):
        reset()
        return
      elif duration > 5000:
        return
    except:
      continue

process()
print "done with autoreset"
exit

I have now got a nice working Arduino hat for the Raspberry Pi

You just need 5 wires:

Raspi Arduino
5V to RAW
GND to GND
Tx to Rx
Rx to Tx
Pin 11 to Reset

After that you can use the Arduino IDE on the Raspi to program the Arduino on /dev/ttyAMA0.
The serial monitor/serial plotter do work like a charm.

The huge advantage is that you get everything without the bulky USB stuff and save a lot of space and power (~30mA less).

It compiles and uploads like a breeze (I am baffled to see that compiling ~900 lines of codes occurs faster on a Raspi 3A, than on an Intel 5i 2200MHz under Windows10)

The only tiny detail ist that, at the end of the successful upload, I keep getting a variable number of
"strace: |autoreset: Broken pipe" errors, that I don't understand.

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

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

Writing | ################################################## | 100% 2.43s

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

Reading | ################################################## | 100% 1.79s

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

Has someone got an idea, what that means, and how to get rid of them? (just for beautifying an already perfect working process).

Thank you.

I too use the pro mini 3.3 wired to my pi just as you have described, including connecting pin 11 on the pi to the rst on arduino.

Just wrote a bash script to wait for avrdude and complete the reset without having to push the reset button. You just need to run the script in a terminal as root before starting the compile/upload in the arduino ide. As soon as the compile is done avrdude starts for the upload. This script waits for avrdude to start and then does the reset for you. Works for me with the sleep values listed, they could be adjusted if needed.

#!/bin/bash

#wait for avrdude
until [[ $(pidof avrdude) ]]
do
        sleep .1
done
echo "avrdude found, do a reset"

#note gpio 17 is the physical pin 11 on the header

#must connect physical pin 11 on the pi
#to the rst pin on the arduino

#export gpio 17
echo "17" > /sys/class/gpio/export

#set to output mode
echo "out" > /sys/class/gpio/gpio17/direction

#set pin to ground/low
echo "0" > /sys/class/gpio/gpio17/value

#adjust this sleep if necessary to time the reset
sleep .5

#unexport to disconnect the pin and cause the reset
echo 17 > /sys/class/gpio/unexport