Reading signal from virtual serial port

electronic-sketch

Note: this post was rescued from my older blog and added it here on Aug 2018. Pinguino project is no longer being developed but the same approach can be used with any Arduino board.

Here I upload the code for a simple task with pinguino: executing a script when you push a button on a circuit.

Documentation: Serial port guide by Michael R. Sweet  – unistd.hread function.

Circuit: simple push-button circuit with a pull-down resistor so when you push you get 5 volts and the led turns on.
Microcontroller: Sends a 1 by virtual serial port when you push the button or a 0 each five seconds.

 Output: The program prints what it gets from the port and if it gets a 1 it executes a script.

sketch

Here is the source code:

Code(1): Signal reading by serial port:

Code (2): Basic signal sending by the virtual serial port for pinguino PIC: