Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider providing a step by step guide to running an Arduino sketch using simavr #345

Closed
TomasHubelbauer opened this issue Aug 22, 2019 · 5 comments

Comments

@TomasHubelbauer
Copy link
Contributor

Hi there, this project looks like exactly what I need from my searching around, but I am not capable of figuring out how to actually use it for my usecase. I have an Arduino sketch which computes some stuff (based on data included in its contents) and writes the results to the serial. I would like to run this sketch using simavr and see the results written to serial in my terminal. I read the readme, the manual (way over my head) and searched through GitHub issues containing arduino, which led me to #270 where I saw @idoc had the same usecase, so I also asked them for the same in that (closed) issue. If they reply, I will PR the project README with the guide after I verify I was able to use it.

@lcgamboa
Copy link

1- Use the Arduino or avr-gcc to compile the sketch to generate the .hex file.
2- Use the patched version of simduino of my fork https://github.com/lcgamboa/simavr/ with option SIMAVR_UART_XTERM=1 and the .hex file.

Obs: avrdude is for transfer the .hex file over serial to arduino bootloader, this is not necessary in your usecase.

You can try my graphic arduino simulator https://github.com/lcgamboa/picsimlab as a "virtual arduino uno" with the Arduino IDE.

@TomasHubelbauer
Copy link
Contributor Author

TomasHubelbauer commented Aug 22, 2019

I tried to use the Arduino CLI to compile the sketch (I don't like the Arduino IDE very much so I try to see if I can do this part using CLI tools only) and it spit out a HEX file and an ELF file, so step one is covered.

For step 2, I found that when using an HEX, the m and f flags are both mandatory, for ELF only the m one is. (m is mcu and f is freq)

When I tried an ELF I got Unable to load firmware.

When I tried a HEX I got Unable to load IHEX file.

Looks like simavr doesn't like HEX/ELF files produced by Arduino CLI. Also the Homebrew installation method seems to not install run_avr and I am not sure if in order to real serial output I need that or simavr suffices. Also I was unable to find any documentation about how the environment variables for terminal output work, even though you mentioned one and another one was mentioned in some open issue.

I tried PicSimLab on macOS using Wine and it looks really great! I ran into an issue tho so I opened it in your repo. I didn't try to use it as a target board with an Arduino IDE yet (like I said above for now I only have Arduino CLI).

@TomasHubelbauer
Copy link
Contributor Author

TomasHubelbauer commented Aug 23, 2019

Closed by mistake. Reopening. I didn't find other issues dealing with either of the two errors, so I'm not sure how to proceed to try and fix either of them.

I did find https://stackoverflow.com/a/7874424/2715716 tho which looks like it could be easy to use to observe the serial. Will try later.

@TomasHubelbauer
Copy link
Contributor Author

I was able to put together instructions for compiling SimAVR on clean Ubuntu and using Arduino CLI to compile a sketch to an ELF for running in SimAVR:

curl -L https://github.com/arduino/arduino-cli/releases/download/0.5.0/arduino-cli_0.5.0_Linux_64bit.tar.gz -o arduino-cli.tar.gz
tar -xvzf arduino-cli.tar.gz
./arduino-cli core update-index
./arduino-cli core install arduino:avr
./arduino-cli compile -b arduino:avr:uno nmea-checksum.ino
apt update
apt install -y build-essential libelf-dev avr-libc gcc-avr freeglut3-dev libncurses5-dev pkg-config
git clone https://github.com/buserror/simavr.git
cd simavr
make
cd simavr
./run_avr -m atmega168 -f 16000000 ../../nmea-checksum.ino.arduino.avr.uno.elf

I'm still at loss about two things:

  • How to execute the setup function of the sketch?
  • How to listen to the serial port?

@lcgamboa mentions the SIMAVR_UART_XTERM environment variable, but I'm not clear on where to go from there. Should just setting it make it so that the serial messages end up in stdout of SimAVR?

@TomasHubelbauer
Copy link
Contributor Author

My bad! With the latest version of SimAVR when running the last line in the above script, run_avr actually correctly outputted the expected serial values… I just mistook them for SimAVR's own logging… 🙄 Really dumb of me, but now that I realized that, I can say this project works perfectly! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants