Skip to content

Upload Arduino sketch from Raspberrypi to RPICT

This article will guide you to upload an Arduino sketch from the raspberrypi directly to the RPICT units.

Audience

DO NOT USE THIS if you have just acquired a RPICT card and trying to get it worked for the first time. This could make things worse for you to troubleshoot later on. If you have landed here after a first purchase you are on the wrong path. Take a good read at the links below first. Raspberrypi_Current_and_Temperature_Sensor_Adaptor#First_time_use Howto setup Raspbian for serial read All RPICT cards are sold with the firmware already installed and configured.

Only use what follows for firmware upgrade or to install an alternative firmware.

Prerequisite

This only works with RPICT units having an atmega328p chip and with autoreset support. Commonly any units being RPICT version 5 and 4.

This won't work with any RPICT unit version 3.0 and RPICT3V1/RPICT3T1.

The atmega328p chip must have bootloader enabled. If not then the bootloader should be burnt with the NanoProg first. If you have acquired the card in or after 2022 this is most probably already enabled.

The command lcl-show-header.py should be used to determine the current firmware being used.

lcl-show-header.py

The firmware name and version will the shown. Stop the command with control C.

Installation

First of all make sure the lcl-rpict-package is installed. This is usually already done if you have setup the Raspberrypi following our instructions.

sudo apt-get install python3-serial wget lechacal.com/RPICT/tools/lcl-rpict-package_latest.deb sudo dpkg -i lcl-rpict-package_latest.deb

Then install avrdude.

sudo apt-get -y install avrdude

legacy

If you had already installed this tool before the 26th September 2022 you should uninstall and re-install avrdude first before running the above.

sudo apt-get remove avrdude

Then run the installation steps as above from the beginning.

Operation

The firmware to upload is a hex file. Usually with .ino.hex extension. In our wiki you should always find the hex file for the firmware.

Upload the file to the RPICT units using the command below:

lcl-upload-sketch.sh sketch.ino.hex

A successful flash will show three progress bars like shown below.

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f (probably m328p) avrdude: safemode: lfuse reads as 0 avrdude: safemode: hfuse reads as 0 avrdude: safemode: efuse reads as 0 avrdude: reading input file "IDCode/QC_02.ino.hex" avrdude: input file IDCode/QC_02.ino.hex auto detected as Intel Hex avrdude: writing flash (6718 bytes):

Writing | ################################################## | 100% 0.96s

avrdude: 6718 bytes of flash written avrdude: verifying flash memory against IDCode/QC_02.ino.hex: avrdude: load data flash data from input file IDCode/QC_02.ino.hex: avrdude: input file IDCode/QC_02.ino.hex auto detected as Intel Hex avrdude: input file IDCode/QC_02.ino.hex contains 6718 bytes avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.71s

avrdude: verifying ... avrdude: 6718 bytes of flash verified

You will also see a bunch of these lines below which you should ignore. They have no negative impact on the process.

strace: |autoreset: Broken pipe

A failing flash will show this type of message below.

avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00

If you are writing the firmware from an arduino sketch (.ino file)

Open your sketch with the Arduino IDE. (This might be on a separate computer, not necessarily on the Raspberrypi).

Run Sketch | Verify/Compile.

This creates a file in the temporary directory of the Arduino software. On a linux system this is inside /tmp/arduino_build_xxxxxx. On windows this could be somewhere like C:\Users\user\AppData\Local\Temp\build4436557367508469592.tmp

If your sketch is named sketch then take the sketch.ino.hex file and copy it over to the raspberrypi.

Credits

Credits go to the SpellFoundry on Github who has well inspired this.