Uploading to AVR using Raspberry Pi GPIO (avrdude GPIO reset)

I edited the post above, due to new user limit :wink:

I notice that when running as root, the gpio4 gets created during sudo pio run -t upload and disappears when command has finished.

@glynhudson is it true? You said me that GPIO 18 should be used.

Opsss. I’ve just changed your level manually. The system is very “smart” :slight_smile:

No, we never fixed this. We came to the conclusion that due to Raspbian root user is needed to access GPIO. I have been living with running pio as sudo to upload. Not ideal, but IMO is not the end of the world since the emonPi is a closed system on a RaspberryPi.

The emonPi uses GPIO 4 (pin 7) as the reset.

Hey :slight_smile: Would be glad for the feedback. I remember that you were interested in Library Managment.

Hi

I 'm trying to load firmware to an ATtiny85 with raspberry pi, it is that possible?

Thanks

It’s possible. PlatformIO works on Raspberry Pi too.

Thanks @ivankravets, the platformio.ini, would look like ?

    [env:attiny85]
    platform = atmelavr
    framework = arduino
    board = attiny85
    board_f_cpu = 1000000L
upload_port =/dev/ttyAMA0

Yes, that is the core idea of PlatformIO to work with the same project settings everywhere with the same manner.

Default use programmer “usbtiny” and I want to use “linuxspi” or GPIO

Is Possible?

Please read docs Redirecting...

You need upload_protocol.

I am try with

“upload_protocol = -P /dev/spidev0.0 -c linuxspi -b 10000”

but next error:
avrdude: Can't find programmer id "-P

Do you have any example of upload_protocol?

Thanks

What are you doing? Please read docs and examples below:

upload_protocol = linuxspi
upload_speed = 10000

and etc… See upload_flags

See program examples Atmel AVR — PlatformIO v6.1 documentation

[env:attiny85]
platform = atmelavr
framework = arduino
board = attiny85
board_f_cpu = 1000000
upload_flags = -P$UPLOAD_PORT

upload_protocol = linuxspi
upload_speed = 10000
upload_port = /dev/spidev0.0

and use pio run -t program.

I am try with

upload_flags = -P /dev/spidev0.0
upload_protocol = linuxspi
upload_speed = 10000

I am doing programming attiny85 with Raspberry Pi, similar to

http://www.instructables.com/id/Programming-the-ATtiny85-from-Raspberry-Pi/ in the step 3

Try this

[env:attiny85]
platform = atmelavr
framework = arduino
board = attiny85
board_mcu = t85
board_f_cpu = 1000000
upload_flags = -P$UPLOAD_PORT

upload_protocol = linuxspi
upload_speed = 10000
upload_port = /dev/spidev0.0
extra_script = extra_script.py

However, that is not enough. You need to make software reset. See

sudo gpio -g mode 22 out
sudo gpio -g write 22 0

We have this software reset on other pins for raspduino and emonpi. Nevertheless, you can write custom extra_script and 2 hooks. Do you familiar with Python?

See my answer here

extra_script.py

Place it on the same level as platformio.ini

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)

P.S: Need to run with sudo. RPi requires it.

I have the next error:

scons: *** Import of non-existent variable ''env''

Please switch to PlatformIO 3.0 Redirecting...

Done

I have the same error with programmer:

avrdude: Can't find programmer id "linuxspi"

it may be that the version of avrdude of platformio does not support this type of controller

I can use the default avrdude the raspberry ?

You need special avrdude. See instruction that you gave me:

git clone GitHub - kcuzner/avrdude: avrdude with a Linux SPI programmer type
cd avrdude/avrdude
./bootstrap && ./configure && sudo make install

Then, need to force PlatformIO use this avrdude. Please edit extra_script.py and before_upload function

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)
    env.Replace(UPLOADER="/path/to/hacked/avrdude")