beta-tester
Posts: 1192
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

upload sketch to standalone ATMega328P via serial port?

Wed Jan 03, 2018 8:51 am

hi,

i have a standalone ATMega328P with a bootloader (like Arduino UNO) on it,
connected to my raspbarry pi via internal serial port (RX, TX & level shifter).

i want to upload new sketches to ATMega328P by using the raspberry Pi's internal serial port, but i don't know how.
i don't want use ISP, i dont't want to use USB-RS232 converter, i don't want to plug the ATMega328P to ArduinoUNO board temporarily to upload sketches. i want to upload sketches via serial port RX,TX + gpio pin and the bootloader that is already on the ATMega328P.

normally uploading a sketch to ATMega328P via serial port, you need TX, RX for communication and DTR to control the reset line, to activate the bootloader at the right time.
but the Raspberry Pi does not provide a DTR line. so how to manage a reset line to the ATMega328p with the correct timing via one of the GPIO and what software/settings i can use to upload new sketches to my standalone ATMega328P.

the serial connection (RX,TX & level shifter) is done already and is working perfectly.
the only question is the DTR line to manage the reset line and what software and settings are needed.
{ I only give negative feedback }
RPi Model B (rev1, 256MB) & B (rev2, 512MB) & B+, RPi2B (1GB), 64GB microSDXC1 class 10, HDMI 1920x1080, keyboard-mouse-combo (wireless), PiCamera, ethernet-cable, 5V/1.2A power supply, Wifi dongle (rt5370)

Idahowalker
Posts: 10
Joined: Wed Jan 03, 2018 5:43 pm

Re: upload sketch to standalone ATMega328P via serial port?

Thu Jan 04, 2018 10:53 pm

I am interested in the ultimate answer to your question but I am not at that place, yet. I am still waiting for OptoIsolators to arrive so I can connect them between the RPi3 and an Uno.

I been working on using the GPIO pins as interrupts. Such as GPIO 4 (J8 pin 4) could be used for the DTR and trigged at the proper time by your code. Right now, that is all the help I can provide but it is a start so you can wire it in to your level shiftier as new ideas / suggestions come along from others.


User avatar
bitbank
Posts: 226
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida
Contact: Website

Re: upload sketch to standalone ATMega328P via serial port?

Sun Jan 07, 2018 2:10 pm

beta-tester wrote:
Wed Jan 03, 2018 8:51 am
hi,

i have a standalone ATMega328P with a bootloader (like Arduino UNO) on it,
connected to my raspbarry pi via internal serial port (RX, TX & level shifter).

i want to upload new sketches to ATMega328P by using the raspberry Pi's internal serial port, but i don't know how.
i don't want use ISP, i dont't want to use USB-RS232 converter, i don't want to plug the ATMega328P to ArduinoUNO board temporarily to upload sketches. i want to upload sketches via serial port RX,TX + gpio pin and the bootloader that is already on the ATMega328P.

normally uploading a sketch to ATMega328P via serial port, you need TX, RX for communication and DTR to control the reset line, to activate the bootloader at the right time.
but the Raspberry Pi does not provide a DTR line. so how to manage a reset line to the ATMega328p with the correct timing via one of the GPIO and what software/settings i can use to upload new sketches to my standalone ATMega328P.

the serial connection (RX,TX & level shifter) is done already and is working perfectly.
the only question is the DTR line to manage the reset line and what software and settings are needed.
Are you using the Arduino IDE on the Pi3? Depending on how many times you need to do this, you don't need to sweat about the DTR line and auto-reset. You can manually hold down the Arduino's reset button, start the upload in the IDE, then release the reset button. You can also avoid using level shifters if you run the Arduino at 3.3v. You can buy them pre-configured that way or modify (in software) one that was sold as being a 5V part by switching to the internal 8Mhz clock.
The fastest code is none at all :)

beta-tester
Posts: 1192
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: upload sketch to standalone ATMega328P via serial port?

Tue Jan 09, 2018 7:31 am

sorry for not answering long time - i was away from keyboard a longer time.
mattmiller wrote:
Thu Jan 04, 2018 11:20 pm
This info on a similar project may help
http://www.farnell.com/datasheets/17781 ... d-onboards
i already took a look to the description of GerdDruino but it looks like it is using ISP instead of RX/TX/(DTR/RESET) to upload new programs.
bitbank wrote:
Sun Jan 07, 2018 2:10 pm
Are you using the Arduino IDE on the Pi3? Depending on how many times you need to do this, you don't need to sweat about the DTR line and auto-reset. You can manually hold down the Arduino's reset button, start the upload in the IDE, then release the reset button. You can also avoid using level shifters if you run the Arduino at 3.3v. You can buy them pre-configured that way or modify (in software) one that was sold as being a 5V part by switching to the internal 8Mhz clock.
i want to use Arduino IDE or avrdude on the RPi.
i want to use it not very often. because it is a custom CNC board i made and only want to upload new firmware as sketch (or hex) from time to time.
the CNC Board is compatible to https://github.com/gnea/grbl/wiki (the firmware is available as sketch and hex file)
the ATmega328p is running with 5V and an external cristal at 16MHz.

i already spend my board a reset button but i didn't know and didn't tried to use it to initiate sketch upload manually :oops:
(because i mean the timing must be within 20ms accurate - only in that time the bootloader is in upload mode)
{ I only give negative feedback }
RPi Model B (rev1, 256MB) & B (rev2, 512MB) & B+, RPi2B (1GB), 64GB microSDXC1 class 10, HDMI 1920x1080, keyboard-mouse-combo (wireless), PiCamera, ethernet-cable, 5V/1.2A power supply, Wifi dongle (rt5370)

User avatar
bitbank
Posts: 226
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida
Contact: Website

Re: upload sketch to standalone ATMega328P via serial port?

Tue Jan 09, 2018 1:41 pm

i already spend my board a reset button but i didn't know and didn't tried to use it to initiate sketch upload manually :oops:
(because i mean the timing must be within 20ms accurate - only in that time the bootloader is in upload mode)
Timing is very forgiving (not 20ms). I ran my board that way until I realized that my usb->serial adapter did expose the DTR line. I didn't find it a problem to load sketches that way.
The fastest code is none at all :)

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 18 guests