Setup
Hi I am trying to use linuxspi with the Arduino MEGA (atmega2560) using a Raspberry Pi 3 Model B+. I have followed the steps in this [thread](https://community.platformio.org/t/uploading-to-avr-using-raspberry-pi-gpio-avrdude-gpio-reset/360?page=2) about the same topic. Here is how my .ini file looks[env:megaatmega2560]
platform = atmelavr
framework = arduino
board = megaatmega2560
upload_flags = -C /etc/avrdude.conf -P$UPLOAD_PORT -b 10000
upload_protocol = linuxspi
upload_port = /dev/spidev0.0
extra_scripts = extra_script.py
And the extra_script.py looks like the following
Import("env")
def _rpi_sysgpio(path, value):
with open(path, "w") as f:
f.write(str(value))
def before_upload(source, target, env):
_rpi_sysgpio("/sys/class/gpio/export", 22)
_rpi_sysgpio("/sys/class/gpio/gpio22/direction", "out")
_rpi_sysgpio("/sys/class/gpio/gpio22value", 0)
def after_upload(source, target, env):
_rpi_sysgpio("/sys/class/gpio/gpio22/direction", "out")
_rpi_sysgpio("/sys/class/gpio/gpio22value", 1)
env.AddPreAction("program", before_upload)
env.AddPostAction("program", after_upload)
I have connected the Arduino ICSP reset pin to GPIO25(pin 22), MOSI to SPI_MOSI GPIO10(pin 19), MISO to SPI_MISO GPIO09(pin 21), 3.3V and GND.
The errors I am dealing with
The current error I am getting is*** [program] /sys/class/gpio/gpio22value: Permission denied
After running on boot
sudo pio run -t program
After the first time running this command, the error changes to the following when running the command
*** [program] Device or resource busy
What I have tried
Made sure I can communicate with the Arduino MEGA through ICSP with the following commandssudo avrdude -p atmega2560 -c linuxspi -P /dev/spidev0.0 -U flash:r:back.hex.i
Which works, so most likely the Arduino is not faulty
I looked up the linuxspi configuration and configured the reset pin to GPIO25 such that the configuration looks like the following now
programmer
id = "linuxspi";
desc = "Use Linux SPI device in /dev/spidev*";
type = "linuxspi";
reset = 25
baudrate = 40000;
-
Changed the extra_script.py to gpio25 everywhere that gpio22 was used or mentioned, this did not change anything
-
Commented out the #env.AddPostAction(“program”, after_upload) this did not change anything.
-
Enabled access to GPIO pins following this stackexchange Access GPIO pins without root. No access to /dev/mem. Try running as root! - Raspberry Pi Stack Exchange. This did not change anything.
Thank you in advance.