keith-packard / snek

Snek programming language for tiny systems
GNU General Public License v3.0
294 stars 30 forks source link

Snek on Arduino Nano #42

Closed helmutg closed 2 years ago

helmutg commented 2 years ago

I am wondering whether it would be possible to run snek on a Arduino Nano. It is very similar to the Arduino Duemilanove and can be programmed in mostly the same way. As far as I can tell, most Nano board should come with optiboot preinstalled. I attempted flashing snek-duemilanove-1.7.hex. To do so, I had to reduce the baud rate passed to avrdude to -b 57600 as that's what the bootloader uses. When booting, it prints Wel<garbage> at baud rate 115200. I suppose that not much is missing to make it do something. I had the impression that it does not work well with higher baud rates, so maybe reducing it is all that is necessary.

drawkula commented 2 years ago

As far as I can tell, most Nano board should come with optiboot preinstalled.

Please double check that.

Arduino Products > Arduino Nano # techspecs mentions:

| Flash Memory | 32 KB of which 2 KB used by bootloader |

That 'smells' like the Duemilanove boot loader.


...some minutes of elevator music...


I did a dive into my electronic sediments for my Nanos, updated the bootloader to Optiboot and then flashed...

(yeti@kumari:36)/tmp/mc-yeti/snek$ /opt/arduino/1.8.15/hardware/tools/avr/bin/avrdude -C/opt/arduino/1.8.15/hardware/tools/avr/etc/avrdude.conf -pATMEGA328P -carduino -P/dev/ARDUINO-NANO-3.0-2 -b115200 -D -U flash:w:snek-uno-1.7.hex:i

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "snek-uno-1.7.hex"
avrdude: writing flash (32242 bytes):

Writing | ################################################## | 100% 12.10s

avrdude: 32242 bytes of flash written
avrdude: verifying flash memory against snek-uno-1.7.hex:
avrdude: load data flash data from input file snek-uno-1.7.hex:
avrdude: input file snek-uno-1.7.hex contains 32242 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 10.84s

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

avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done.  Thank you.

Connecting via...

(yeti@kumari:36)/tmp/mc-yeti/snek$ screen /dev/ARDUINO-NANO-3.0-2 115200

...showed the expected prompt:

Welcome to Snek 1.7
> █

Sweet!

Now I need to code some Snacks for Sneks?

helmutg commented 2 years ago

Wow. So all that needs doing here is updating the documentation to say that Nano works like the Duemilanove. And me updating my bootloader...

drawkula commented 2 years ago

Maybe some Nano clones indeed come with Optiboot preinstalled now, but the baud rate you saw hints to the Duemilanove boot loader which I had on my some years old Nano clones too.

keith-packard commented 2 years ago

Seems like it would be nice to have instructions for switching to optiboot. I seem to recall an arduino package that you would build and run using the old boot loader that would switch the device to optiboot. Might be nice to at least provide links to that?

drawkula commented 2 years ago

I only remember Micronucleus updates in place via a "normal sketch".

Maybe someone else has the link to in place upgrades to Optiboot? Is changing the fuses without an ISP possible at all?