You must have met similar situations: your code is downloaded to the board but doesn’t work out as you have predicted. How to deal with it... At that time, you’ll need to debug your code.
There are two common ways. One is to step through it, which is not supported. So the best way by now is to print the information out. Then you could judge which step goes wrong according to the info.
Let’s see how it works.
After each line of code that is related to a value, you could add
print() function to view it, in case of any unexpected mistakes. Then download the code to your board.
Now you will need to change the USB connection from the download port to the serial port.
SwiftIO board has two ports: download port and serial port. They might be quite confusing at the beginning.
Download port allows you to download code to your board.
Serial port is for serial communication between your board and computer. Serial communication is commonly used on microcontrollers, however, the computer hardly uses it, so a serial to USB converter is added to the board to allow the data transmission between them. It is an independent part reserved for this use.
Click on the serial monitor button in the upper right corner.
Select the matched UART Port as the second image. If you can't find it, don't worry. Close the Serial monitor, wait a while, then open it again.
After successfully connected, the values will be printed out.
If there is something wrong when executing the code, you would notice the code is blocked at a certain step, and the following value will not be printed. Then you could infer if the board crashed or some steps go wrong.
If the code works normally, you could pay attention to the values: maybe they are out of range, or the calculation formula is wrong by accident, and so on.