Chapter 10 - Physical computing - Inputs & Outputs

Physical Computing : 

One of the most exciting things about Learning electronics or robotic kits in recent years is their potential for physical computing

Physical computing connects the digital world inside a computer to the physical world, using various peripherals such as LEDs, motors, sensors, and even cameras to some extend. 

wiki:  https://en.wikipedia.org/wiki/Physical_computing



Senses & actuator:

So for us humans, we have our five senses: sight, sound, smell, touch & taste.

Imagine someone calling out to you. He made a sound so you can "see"(hear) such input as a sound signal. If the sound is not coming from in front of you, you can "move" (turn around) output depending on the sound direction.

Or maybe you smell something burning. So that's an input.
This smells something burns is the input and the output is your reaction. So our muscles tighten & relax, we move. That's an output.

In a similar fashion, any device, even a robot, needs some sort of input & output.



 Basic input & output in Arduino?

Although we have done many LED blinking exercises in the past chapters, we haven't actually looked at any Inputs yet.

For a complex microcontroller of today, each pin could potentially hold multiple functionalities depending on how you configure them in your firmware. Shown below is a simplified illustration of how one pin on your microcontroller is like.



The IO pin would normally start off as an input only pin upon power cycling. In Arduino, we can use the following function call to initialize the pin as a input or output.

pinMode(PIN, PinDirection);


The most basic would be as INPUT and OUTPUT. Configuring a pin as:

INPUT is similar to putting them as a high-impedance state. In this mode, Input pins make extremely small demands on the circuit as they are sampling, equivalent to a series resistor in the megaOhm in front of the pin.

Pull-up resistors are often useful to steer an input pin to a known state if no input is present. This can be done by adding a pull-up resistor, or a pull-down resistor (resistor to ground) on the input. Some microcontroller pin have internal pull-up resistor build in, and this feature could be activated through setting the pinMode() as INPUT_PULLUP.
Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state. This means that they can provide a substantial amount (Not a whole lot) of current to other circuits.


Read & Write:
We have seen the capability of the C3 CoreModule in driving it's onboard LED through the Arduino function.

digitalWrite(PIN, STATE);

I am sure you are curious about how to sample input from the physical world. Arduino has provided an easy-to-use function just to do that.

digitalRead(PIN);


 Input-Output Example:

We will (for the last time) use the onboard LED and Switch the demonstrate the simple Input & Output in the Arduino ecosystem. 
The button found on the CoreModule has a weak physical pull-up resistor & it is connected to IO9 pin on the ESP32-C3 microcontroller.


 Todo:

  • Phew... Chapter 10, we have come a long way. I would like you to implement a multi state button press as shown in the diagram below.
    This kind of user interaction is found in some low cost electronics gadget with a single button. e.g, LED light, Portable fan speed.



     Did you realize the Button press is blocked by while the LED is blinking (non-responsive)?

     Maybe some supplement may help?

  • (Advanced) How about achieving the same thing with Threads? 
    C3 CoreModule support the POSIX PThread API, making it relatively easy to implement multi-thread application/firmware.
    PThread:  Posix Thread Programming


    Multi-mode LED blinker sketch utilizing PThread library: 
     Solution

    As we move forward, you will often see links pointing to  Github.
    e.g. The RISC-V Arduino® Add-on supplied by Espressif, Arduino native support, Almost all source code to various Open Source project... and the list go on...


  • Pretty sure every one here has some experience with a variety of Electronics gadget. What other ways of interacting with a push button switch can you think of?
  • How about Long-press or Press & hold. Can you implement as an Arduino sketch?