OttoDIY / blockly

Otto Blockly; a fully integrated graphical programming for any type of Arduino projects, including robots, ready to install in your computer, it works offline and also online
https://www.ottodiy.com/software
GNU General Public License v2.0
118 stars 80 forks source link

Cannot upload generated code to Arduino Nano with Optiboot (new) bootloader, Arduino Every #2

Closed BodoMinea closed 4 years ago

BodoMinea commented 4 years ago

Sorry if this is already addressed in some update, I couldn't find one through easy means - automatic update / GitHub.

On the local build of OttoDIY Blockly, obtained through the official website, which is definitely based on this, it is apparently not possible to compile and upload code suited for the new Arduino Nano variants which come with the OptiBoot bootloader. This requires higher code upload speed (BAUD 115200).

This also seems to be causing problems for other people on the forum:

My now open Pull Request #1 aims to solve this problem.

cparrapa commented 4 years ago

Hi @BodoMinea I am working in another update but i did not have this issue. I will for sure have a look i have a couple of new Arduino Every and BLE that i can test with, but did you have this problem also with old nanos?

I would also like to link this repo with the auto update in the local Build of Otto Blockly that now is with the wrong fork. And have them sync so that we can continue working on improvements directly.

Thanks a lot for your contribution! i wish you can help us more. đź‘Ť

BodoMinea commented 4 years ago

Hi, no, this is not about the Arduino every or BLE or some new variant with feature additions. Not an old clone either (those are actually working properly and this is how I diagnosed the issue - old nano compiles and uploads, new arduino compiles and upload hangs, and I do have the CH340 installed because I sometimes program NodeMCU boards). It is a newly built, regular Arduino Nano acquired from a local supplier. The only difference is the bootloader. This one has an upgraded bootloader which requires a higher upload speed.

You can see this issue discussed on another project which requires uploading to Arduino boards back in 2018: https://github.com/twinearthsoftware/ArduinoSketchUploader/issues/32

Also discussed on SE: https://arduino.stackexchange.com/questions/804/arduino-nano-uploading-gives-error-avrdude-stk500-recv-programmer-is-not-re

Also people complaining of some Arduino boards referencing this: https://www.amazon.com/gp/customer-reviews/RW6XCPCYF030F?ASIN=B0713XK923

I wish you good luck and hope you'll keep up the good work with the updates and everything! If you need more information I'll be around.

cparrapa commented 4 years ago

Hi @BodoMinea thanks I am just thinking how is gonna be in the menu? (since it could be confusing for people) Do you think we can make this for the new Arduino Nano every?

Would you like to join us for more improvements?

BodoMinea commented 4 years ago

Untitled This is how it looks like in the Arduino IDE, and the only way to find out what works with your board is on a trial and error basis. If it doesn´t work just switch to the other one. I implemented a similar strategy to the best extend I could in your project with my limited experience on it: Untitled2 These boards, the new/old Arduino Nano which are physically identical but differing in Bootloader (and thus sketch upload speed). This is how they are differentiating the boards that are referenced in this issue in the config files of the Arduino IDE:

##############################################################

nano.name=Arduino Nano

nano.upload.tool=avrdude
nano.upload.protocol=arduino

nano.bootloader.tool=avrdude
nano.bootloader.unlock_bits=0x3F
nano.bootloader.lock_bits=0x0F

nano.build.f_cpu=16000000L
nano.build.board=AVR_NANO
nano.build.core=arduino
nano.build.variant=eightanaloginputs

## Arduino Nano w/ ATmega328P
## --------------------------
nano.menu.cpu.atmega328=ATmega328P

nano.menu.cpu.atmega328.upload.maximum_size=30720
nano.menu.cpu.atmega328.upload.maximum_data_size=2048
nano.menu.cpu.atmega328.upload.speed=115200

nano.menu.cpu.atmega328.bootloader.low_fuses=0xFF
nano.menu.cpu.atmega328.bootloader.high_fuses=0xDA
nano.menu.cpu.atmega328.bootloader.extended_fuses=0xFD
nano.menu.cpu.atmega328.bootloader.file=optiboot/optiboot_atmega328.hex

nano.menu.cpu.atmega328.build.mcu=atmega328p

## Arduino Nano w/ ATmega328P (old bootloader)
## --------------------------
nano.menu.cpu.atmega328old=ATmega328P (Old Bootloader)

nano.menu.cpu.atmega328old.upload.maximum_size=30720
nano.menu.cpu.atmega328old.upload.maximum_data_size=2048
nano.menu.cpu.atmega328old.upload.speed=57600

nano.menu.cpu.atmega328old.bootloader.low_fuses=0xFF
nano.menu.cpu.atmega328old.bootloader.high_fuses=0xDA
nano.menu.cpu.atmega328old.bootloader.extended_fuses=0xFD
nano.menu.cpu.atmega328old.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex

nano.menu.cpu.atmega328old.build.mcu=atmega328p

## Arduino Nano w/ ATmega168
## -------------------------
nano.menu.cpu.atmega168=ATmega168

nano.menu.cpu.atmega168.upload.maximum_size=14336
nano.menu.cpu.atmega168.upload.maximum_data_size=1024
nano.menu.cpu.atmega168.upload.speed=19200

nano.menu.cpu.atmega168.bootloader.low_fuses=0xff
nano.menu.cpu.atmega168.bootloader.high_fuses=0xdd
nano.menu.cpu.atmega168.bootloader.extended_fuses=0xF8
nano.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex

nano.menu.cpu.atmega168.build.mcu=atmega168

Pay attention to the upload speeds. Also notable: this difference between Arduino boards in the IDE board select was not here from the start, they introduced it with a board package update (AVR package 1.6.21) and later new IDE package, for example I found this file in this version in the Arduino IDE appdata board packages folder, not in the Program Files, but on a new install it comes in the program files. The website-downloaded Otto Blockly only supports the Arduino Nano w/ ATmega328P (old bootloader) out of the box, with 57600 upload speed. Based on the values in the above files, I edited the boards.js in your project accordingly: https://github.com/OttoDIY/blockly/blob/89663ef77b8c2bb044c3ac72ca570406839488e6/js/boards.js

I am willing to help you further with this project. I do not have an Arduino Nano Every board but I did a little digging - installed the Mega AVR package in Arduino IDE through the Boards Manager and explored the boards.txt properties. It still uploads with avrdude, on BAUD 115200 (like the OptiBoot Nano I added) but also has a different CPU - atmega4809. Based on the Arduino IDE provided file:

##############################################################

nona4809.name=Arduino Nano Every

nona4809.vid.0=0x2341
nona4809.pid.0=0x0058

nona4809.upload.tool=avrdude
nona4809.upload.protocol=jtag2updi
nona4809.upload.maximum_size=49152
nona4809.upload.maximum_data_size=6144
nona4809.upload.speed=115200
nona4809.upload.use_1200bps_touch=true
nona4809.upload.extra_params=-P{serial.port}

nona4809.build.mcu=atmega4809
nona4809.build.f_cpu=16000000L
nona4809.build.board=AVR_NANO_EVERY
nona4809.build.core=arduino
nona4809.build.variant=nona4809
nona4809.build.text_section_start=.text=0x0
nona4809.build.extra_flags={build.328emulation} -DMILLIS_USE_TIMERB3 -DNO_EXTERNAL_I2C_PULLUP
#nona4809.build.extra_flags=-B{runtime.tools.atpack.path}/gcc/dev/{build.mcu}

nona4809.bootloader.tool=avrdude
nona4809.bootloader.file=atmega4809_uart_bl.hex
nona4809.bootloader.SYSCFG0=0xC9
nona4809.bootloader.BOOTEND=0x00
nona4809.bootloader.OSCCFG=0x01
nona4809.fuses.file=fuses_4809.bin

menu.mode=Registers emulation
nona4809.menu.mode.on=ATMEGA328
nona4809.menu.mode.on.build.328emulation=-DAVR_NANO_4809_328MODE
nona4809.menu.mode.off=None (ATMEGA4809)
nona4809.menu.mode.off.build.328emulation=

##############################################################

The addition to boards.js in Otto Blockly could look something like:

nona4809: {
        description: "Arduino Nano Every",
        BUILTIN_LED: 13,
        picture : "media/nano-every.jpg",
        dropdownPWM: [["3", "3"], ["5", "5"], ["6", "6"], ["9", "9"], ["10", "10"]],
        dropdownAnalog: [["A0", "A0"], ["A1", "A1"], ["A2", "A2"], ["A3", "A3"], ["A4", "A4"], ["A5", "A5"],["A6", "A6"],["A7", "A7"]],
        interrupt: [["2", "2"], ["3", "3"]],
        serial: [['300', '300'], ['600', '600'], ['1200', '1200'],
                ['2400', '2400'], ['4800', '4800'], ['9600', '9600'],
                ['14400', '14400'], ['19200', '19200'], ['28800', '28800'],
                ['31250', '31250'], ['38400', '38400'], ['57600', '57600'],
                ['115200', '115200']],
        serialPin: [["Rx/Tx", "0"]],
        build: "nona4809",
        cpu: "atmega4809",
        speed: "115200",
        prog: "arduino",
        usb: "mini USB",
        voltage: "5V",
        inout: "20"
    }

(I cannot verify all the values without a sample board at this time but I changed some according to the spec page at https://store.arduino.cc/arduino-nano-every - also this board apparently supports interrupts on all pins so interrupt should be changed, and also picture added - https://store-cdn.arduino.cc/uni/catalog/product/cache/1/image/520x330/604a3538c15e081937dbfbd20aa60aad/a/b/abx00028_featured_1.png )

cparrapa commented 4 years ago

How can you know if you have one nano or the other by trying both uploaders?

BodoMinea commented 4 years ago

If you choose the wrong option, it will stay for a long time on „Uploading” and then fail with:

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x49
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x4c
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x49
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x39
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x33
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x34
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x31
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x54
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x65

avrdude done.  Thank you.

An error occurred while uploading the sketch

Basically the board will not respond to the wrong sketch upload speed and the serial uploader will just wait until it times out.

Maybe coding in some warning into the project would help (there's none in arduino). Something like: „Cannot upload to your Arduino Nano board? Try the different revision versions in the menu.”

cparrapa commented 4 years ago

Yes in terms of User experience specially for beginners i would like to add some warning, maybe we need to increase the help section or at least make it clear in the forums

BodoMinea commented 4 years ago

Yes. The PR is merged now and theoretically we could close this issue. Do you want to add the supposed Arduino Every variant even though it is not tested? I could do that. And maybe also code in the warning.

cparrapa commented 4 years ago

Yes that would be great please, i have all the "real new nanos" here (every, iot and BLE) so that... i could test now. There is also few community members loyal to Arduino that would love this.

Thanks!

BodoMinea commented 4 years ago

I put in Pull Request #3 for adding the Arduino Nano Every which I could not test.

It's a little bit different for the Arduino Nano 33 BLE. The Every is still a „regular AVR”, while the BLE runs on Cortex CPU, has native USB and has a different upload tool „openocd” which does not set an upload speed, at least in the Arduino IDE config files. I'm not sure this can be added to Otto Blockly as easily as editing the boards.js file. I think the compilation and upload processes need to be fired up differently.

cparrapa commented 4 years ago

well at least having the nano every is a good start thanks!

cparrapa commented 4 years ago

I just build the APP and once i try to check the code in Blockly with Arduino Nano selected i get Error: Command failed: verify.bat nanooptiboot Board nanooptiboot (platform avr, package arduino) is unknown With Arduino Nano every selected i get Error: Command failed: verify.bat nona4809 Board nona4809 (platform avr, package arduino) is unknown With Arduino Nano (Old Boot loader) seems ok which is the one were using as the main before, maybe we can call this one Otto DIY to avoid confusions.

BodoMinea commented 4 years ago

Yes, I think there are some changes that need to be done in the Arduino Core that ships with blockly (put by installer into install directory). When I started contributing to this project, the Arduino part of it was not on the repo. I still do not know how this is installed locally (the board definitions in the Arduino Core seem to be missing, locally I copied them from my Arduino installations).

There's the compilation/arduino folder in the repo, but the boards.txt file is not there.

Can you give some insight into how the Arduino Core / Libraries are added to the local installation? Is there some archive / download / script taking place in the install phase (NSIS)?

cparrapa commented 4 years ago

Hi @BodoMinea

I was actually doing similar approach just copy the whole compilation/arduino folder from blocklino, which is necessary to have a local working installer or software, there is an .exe file there but i am not sure if is supposed to install before building the electron app.

That is why i added to have all in one place and also because i saw it was important in other blockly arduino repos.

It must be something related to arduino cli

BodoMinea commented 4 years ago

Hi, I looked into the problem. I can help you solve the old/new Arduino Nano part of it by providing my full installation folder.

You can get it from here: https://drive.google.com/open?id=1m0rDPZVmRO6X6Ue8MmQBH4P6cFzYPU

The files regarding Arduino platforms and board definitions are not in the repo so a commit will not help.

The archive above contains the current Github version of Otto Blockly and the necessary files and definitions (bootloader files, etc.) to make all Arduino Nanos (except de Every work). You can bundle this into the NSIS installer.

I do not think I will be able to finalize the same tricks for the Every until I get a board on my hands to actually try.

cparrapa commented 4 years ago

Hi so how about we upload the arduino platforms and boards definitions in a new pull request? i just dont understand how other blockly arduino repos did it they always just have the repo like we have.

how to bundle in the NSIS installer?

I will try in every but better not to release this feature until is tested for all nanos Thanks

cparrapa commented 4 years ago

@BodoMinea you can see here we still have this issue with this update, only the old bootloader works and sounds weird for beginners. Maybe this one we just call it Otto since is the one we use with our nano boards.

image

BodoMinea commented 4 years ago

@cparrapa yes, I know this issue is still ongoing and I'm looking into possible solutions. The thing is that the referenced files where the 'nanooptiboot' parameters are missing, are not to be found and therefore modified in this repo, but they are in the local otto blockly install. So basically, when I initially got Otto Blockly from the otto website, these files that are not in this repo were installed (by the installer, one example of this file is boards.txt). Do you know how this executable installer that is on the website is produced or by who? That's the only way we can update it. These are Arduino related files that the installer puts into the 'compilation' folder at install time. Thanks.

cparrapa commented 4 years ago

@BodoMinea as you see in Blocklino repo is also like that but somehow the arduino files are produced when packing i guess, this should be something related with Arduino CLI but i am also in the process of learning how it works this compiler.

Thanks for taking some time to help!

cparrapa commented 4 years ago

good news! @BodoMinea with your boards.txt file i manage to fix the next release for Arduino Optiboot(new), apparently that is the only file that needed to be changed, i also added Arduino Every inside that .txt, but i am not sure if the parameters are working, at least the check does not give errors