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.
Applies to models
This guide does not apply to models RPICT3T1 RPICT3V1 or RPIZ_CT3T1 RPIZ_CT3V1.
This applies to models
RPICT8/RPICT7V1/RPICT4V3 versions 3/4/5/6
RPICT4W3T1 v5
Note there is a special section for version 3 cards down below.
Prerequisite
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
For Version 6 boards use instead
lcl-upload-sketch.sh sketch.ino.hex -p avr32db32
For RPICT3V1T1 board use instead
lcl-upload-sketch.sh sketch.ino.hex -p avr32db28
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.
Version 3 cards
Version 3 cards are special because this ability to flash a firmware from the Pi did not exists when the version 3 were designed.
Nevertheless it is still possible to use it.
Just before launching the lcl-upload-sketch.sh
command press the white reset button and hold it. Then launch the command and immediately release the reset button. The firmware should be written.
If it does not have several attempt it might be because the mcu does not have any bootloader.
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.
Credits
Credits go to the SpellFoundry on Github who has well inspired this.