Debuging my code in PC without REPL
Debuging my code in PC without REPL
Greetings,
I am currently developping a weather monitoring station with my pyboard. I have been using the REPL tool to debug some parts of my code.
The next step would be to debug the hole code working together by outputting a lot of specific values (sensor readings, relay states) to my pc via a serial port. By debuging I mean to see the values that my sensors and/or functions generate in order to see if they are correct.
For those who have used Arduino before, I am looking for a solution like "Serial.println("values that I want to see") with a console in my PC listening to the serial port.
I guess I should use a serial port since I haven't been able to paste all the code in the REPL tool (problem with indentations).
My question is: What are the options to see values generated by the pyboard in my pc? It's a lot of values so the LCDs are not an option.
Just for informaiton: My temporary solution for now is by connecting the uart(3) port to one of the arduino mega serial ports, send the messages from my pyboard and then the arduino prints the message to the usb serial port. It works almost perfectly but when I send a string to the arduino from my pyboard, the arduino outputs the decimal ascii value of each character and one line for each ascii value/character. I will maybe work on the arduino code but I would like to have another solution in orther to have most of the pyboard pins available.
Thank you for your support.
Best reagrds,
Schvic
I am currently developping a weather monitoring station with my pyboard. I have been using the REPL tool to debug some parts of my code.
The next step would be to debug the hole code working together by outputting a lot of specific values (sensor readings, relay states) to my pc via a serial port. By debuging I mean to see the values that my sensors and/or functions generate in order to see if they are correct.
For those who have used Arduino before, I am looking for a solution like "Serial.println("values that I want to see") with a console in my PC listening to the serial port.
I guess I should use a serial port since I haven't been able to paste all the code in the REPL tool (problem with indentations).
My question is: What are the options to see values generated by the pyboard in my pc? It's a lot of values so the LCDs are not an option.
Just for informaiton: My temporary solution for now is by connecting the uart(3) port to one of the arduino mega serial ports, send the messages from my pyboard and then the arduino prints the message to the usb serial port. It works almost perfectly but when I send a string to the arduino from my pyboard, the arduino outputs the decimal ascii value of each character and one line for each ascii value/character. I will maybe work on the arduino code but I would like to have another solution in orther to have most of the pyboard pins available.
Thank you for your support.
Best reagrds,
Schvic
Re: Debuging my code in PC without REPL
You definilty don't want to see output through usb connection? Because you get all print() you do on your pyboard, even when running a script in flash...
Frédéric
-
- Posts: 288
- Joined: Sun May 04, 2014 8:54 am
Re: Debuging my code in PC without REPL
Amusing the code you want to debug looks like this:
(Warning - not tested, using Accleromter as example)
1. Save that script on the pyboard, either flash or sd, doesn't matter. Name it test.py
2. Open the REPL.
3. Type to run your script on the REPL.
4. You will see the values printed to your screen. It will be hard to read tough, because it will run really fast. You can add after the print to slow it down.
Hope that helps, keep asking if not.
(Warning - not tested, using Accleromter as example)
Code: Select all
import pyb
accel = pyb.Accel()
while True:
ax, ay ,az = accel.filtered_xyz()
print(ax, ay, az)
2. Open the REPL.
3. Type
Code: Select all
import test
4. You will see the values printed to your screen. It will be hard to read tough, because it will run really fast. You can add
Code: Select all
pyb.delay(100)
Hope that helps, keep asking if not.
Re: Debuging my code in PC without REPL
Many thanks for your answers, it works perfectly by creating a file and printing what I want.
I jsut saw there is also a function called pyb.repl_uart(), I will see how it works.
I am now wondering if there is a way to give inputs to the pyboard via the REPL tool when it is executing the code in the main.py file. What do you think?
Many thanks again.
I jsut saw there is also a function called pyb.repl_uart(), I will see how it works.
I am now wondering if there is a way to give inputs to the pyboard via the REPL tool when it is executing the code in the main.py file. What do you think?
Many thanks again.
Re: Debuging my code in PC without REPL
There are a couple of ways of waiting for input.
You can poll the USB to see if data is available: see http://micropython.org/doc/module/pyb/USB_VCP
I wrote a sample program to query what keys are being pressed:
https://github.com/dhylands/upy-example ... er/keys.py
You can use the input command:
You could write your logging information to a log file (on the sdcard), which you then collect later.
If you're running on a linux host, I have an auto-connecting terminal program written in python:
https://github.com/dhylands/usb-ser-mon
It creates a log file called usb-ser-mon.log which records everything typed and received over the serial port.
You can poll the USB to see if data is available: see http://micropython.org/doc/module/pyb/USB_VCP
I wrote a sample program to query what keys are being pressed:
https://github.com/dhylands/upy-example ... er/keys.py
You can use the input command:
Code: Select all
>>> x = input("Enter some data> ")
Enter some data> Hello
>>> x
'Hello'
>>>
If you're running on a linux host, I have an auto-connecting terminal program written in python:
https://github.com/dhylands/usb-ser-mon
It creates a log file called usb-ser-mon.log which records everything typed and received over the serial port.
Re: Debuging my code in PC without REPL
I will experiment with this functions to see how they perform for my application. Concerning the logging function I will stick for now with the REPL solution since it is real time debuging while the application is executing so I can test different configuraitons. The logging function is interesting for analysing the measurements after long periods of acquiring data.
I have an additional question regarding the states of the pins: If a pin is an output and I want to see its state, I should just execute: mypin.value()? I have tried it and it works but apparently it blocks its state. It works in the hardware side but in the software side it keeps teling it is activated even if in the hardware side it is not.
Thank you very much.
Best regards.
I have an additional question regarding the states of the pins: If a pin is an output and I want to see its state, I should just execute: mypin.value()? I have tried it and it works but apparently it blocks its state. It works in the hardware side but in the software side it keeps teling it is activated even if in the hardware side it is not.
Thank you very much.
Best regards.
Re: Debuging my code in PC without REPL
I'm not quite sure I understand. I did the following:schvic wrote:I have an additional question regarding the states of the pins: If a pin is an output and I want to see its state, I should just execute: mypin.value()? I have tried it and it works but apparently it blocks its state. It works in the hardware side but in the software side it keeps teling it is activated even if in the hardware side it is not.
Code: Select all
>>> pin = pyb.Pin('LED_GREEN', pyb.Pin.OUT_PP)
>>> pin.value(1)
>>> pin.value()
1
>>> pin.value(0)
>>> pin.value()
0
Re: Debuging my code in PC without REPL
Oh, yes, sorry I just saw the error in my code. Thank you for the information, before I used the pin.high() or pin.low() to set the output values but it's better pin.value(1or0).
Re: Debuging my code in PC without REPL
pin.high and pin.low should be fine as well:
pin.high() and pin.value(1) are doing exactly the same thing. Similarly pin.low() and pin.value(0) are also doing exactly the same thing.
Code: Select all
>>> pin = pyb.Pin('LED_GREEN', pyb.Pin.OUT_PP)
>>> pin.high()
>>> pin.value()
1
>>> pin.low()
>>> pin.value()
0
Re: Debuging my code in PC without REPL
Thank you, the error was because of the conditions for changing the value of the variable. The pin.value() method is more practical tu use