Week 4

Helloooooooooo, still here, this week was about microprocessor programming, I thought it was easier, and it is easy, is just that is different from programming just in python. There are many things to know to run a program. But first...

What is a micro controller?

A microcontroller is kind of a head of a machine, is the thing that processes all the given information. This things have 3 main things, the code, the sensors and the actuators, within the physical part (sensors and actuators) there is every electronic component, and this electronic components work according to the given code. The code are the instructions of what to do with every connected component. The code can be written in many languages such as, micropython, arduino, c++, rust, etc. Also, is important to mention that there are many many MANY types of micro controllers, from arduino, raspberry pi pico, tiny, and many many other.
NOTE, is important to read the information sheet of the micro controllers to know what does it offer and pick the one which more adjust to your necessities.
NOTE2, many micro controllers can be programed with different languages, not using 2 languages at the same time, you have to install the language and if you want to change language you have to desinstall the language and install the new one and so rewrite the hole code.

The micro controller I chose

Well I didn't picked it but is what our fablab will give us: raspberry pi pico

pipico
To pick the right micro controller we have to read the data sheet, in this case this link is from the pi pico, some important things to look at are: This one has a RP2040 micro controller, 2MB of Flash memory, SRAM of 264kB, Operation voltage of 3.3V and 5V, 26 digital Pins,

The first steps are

  1. Pick the right micro controller
  2. Install the language on the micro controller
  3. Select he pins for physical electronic components
  4. Write the program
  5. Make the physical circuit
  6. Test

How to program a micro controller?

Now it's time to start programming, here is very important to keep in mind the libraries, this are like packages of information that allows you call some predefined commands with specific functions and make the programming process a lot easier.
In my case I just used machine and utime.

machine


Allows you to call the inner functions of the micro controller like: Pin and timer. Pin means literally to the pins of the micro controller, where the electronic components are plugged. And timer calls for the timer of the micro controller and allows you to make interruptions.

utime


utime means micro time, this library is mostly used because of sleep this command literally turn "off" the hole micro controller for a specific time.
Once done with the libraries the second step is to declare your variables and pins (which are also a variable). The led is the easiest one to declare because you're just declaring an output at a certain pin.

led = machine.pin(0,Pin.OUT)

this is a led = call the class "pin" form the machine library (led is on pin 1, and this pin is an output)



But for a push button is a different story, you hav to declare it with a push down or push up line. This line will tell the micro controller in which position start the pin, for pull_DOWN it will start on a low position (0) and once pressed the button it will change to UP (1). For example:

boton = machine.Pin(0,machine.Pin.IN, machine.PULL_DOWN)

this is a button = call the "Pin" class of the machine library (this button is on Pin 0, this is an input, and start this button in LOW position)


For example:
ejemplos pines
This image shows the state of the pins we declared, the led is an output, the button is an input with pull-down resistor.

Important concept

PWM means "pulse with modulation", and this is basically a way of controlling pulses. Think about it like a every day up and down continuos signal, 0 and 1. Where the amplitude will be the voltage (just off or on), the period is the complete cycle, and a cycle has an up section and a down section.
PWM example
This kind of pulses are defined by the percentage of up time (called "duty" when programming). So for example, if we have a period of 1 second with a max voltage of 5V and a duty of 50% the led will turn on 0.5 seconds and will turn of for 0.5 seconds. A duty of 30%, the led will turn on 0.3 seconds and turn of 0.7 seconds.

What I did

I wanted to do a lot more things but, I couldn't JAJAJA SAD, so I ended up doing a "copy" program. This program asks you for a period of time, activates a buzzer to tell the beginning of the data capture, and you have to press a push button whenever you want within the given time. When the time is over the led will turn on the same time and order you pressed the button.
NOTE I used wokwi to make this simulations, this website has arduino, pico pi, ESP32 micro controllers and many languages like, arduino, micropython, and rust.
NOTE2 I used micropython, I've worked with python before and is one of the easiest programming languages.


Here is my code

And here a little demonstration of how it works.