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

How to read on the serial port of the arduino simulated program? #36

Open
Vincent14 opened this issue May 12, 2017 · 1 comment
Open

Comments

@Vincent14
Copy link

Well.. my arduino sketch contains this code:

void setup() {
   Serial.begin(115200);
}

And my first try in Python looks like this:

from pysimavr.sim import ArduinoSim

print "Start"

arduino = ArduinoSim(mcu='atmega2560', external_elf='meuhcube.hex')

while True:
  arduino.get_serial()

But, this ends in an infinite loop without anything on the output and I can't Ctrl+C the terminal, I must close the window or my CPU just burns in place, any idea?

I don't know if I can ping you in every of my issues @Premik, you're so helpful, thank you in advance.

@Premik
Copy link
Contributor

Premik commented May 13, 2017

  • get_serial() is just a selector which gives you the Uart object. I think you are probably calling it in an endless loop. Which is not what you want. You only call the get_serial once and it should run the simulation on a background thread (if my understanding is correct). So instead of the while loop you can just do for example input("Press Enter to exit...")
  • I really recomend you to peek into the sources of pysimavr. It is pretty self-documenting :-). The sim.py is just like two pages of code. In the tests there are test_sim.py and test_udp.py which might give you some better clue about the serial usage.
  • It could also happen the simavr core has crashed before you even get the Uart object back. In some cases the python main thread could die silently and then only sigkill helps. This was fixed in Set child thread to daemon to avoid python hang. #25 but not released yet.
  • It might be worth try loading the .elf file instead of the .hex. It should be in the same folder.

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