4. Embedded programming¶
This week I worked on defining my final project idea and started to getting used to the documentation process.
- Group assignment:
š° Search for different types of microcontrollers boards and compare between them.
š° Search for different programming languages, compare between them and how many can you use to program the same microcontrollers.
- Individual assignment:
š° Read the datasheet for the microcontroller board you are programming.
š° Program the board you have to do something, with as many different programming languages and programming environments as possible. (two at least)
What is a microcontroller?¶
āA microcontroller is a compact integrated circuit designed to govern a specific operation in an embedded system. A typical microcontroller includes a processor, memory and input/output (I/O) peripherals on a single chip.ā
What is programming?¶
āProgramming refers to a technological process for telling a computer which tasks to perform in order to solve problems. You can think of programming as a collaboration between humans and computers, in which humans create instructions for a computer to follow (code) in a language computers can understand.ā
What is code?¶
āA system of symbols (such as letters or numbers) used to represent assigned and often secret meanings.ā
The type I am using is Arduino MKR WIFI 1010 Sense.
āThe Arduino MKR WiFi 1010 is the easiest point of entry to basic IoT and pico-network application design. Whether you are looking at building a sensor network connected to your office or home router or creating a Bluetooth and low-energy device sending data to a cellphone, the MKR WiFi 1010 is your one-stop solution for many of the basic IoT application scenarios.ā
Useful links¶
Easy mode:Ā ā£Blink your LED but have your blink delay periods be randomized values between 1 second and 5 secondsĀ ā£ā£
Code Example¶
Easy mode:Ā ā£Blink your LED but have your blink delay periods be randomized values between 1 second and 5 secondsĀ ā£ā£
PinMode (LED_BUTLTIN, OUTPUT) ;
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(5000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
}
Medium mode:Ā ā£ pre code your microcontroller to send a Morse code 1 word message and challenge a friend, family member, your colleagues or your instructor to figure it out. (Refer to the schedule)
Word SNOW https://youtube.com/shorts/WA1j8ZlHxEE?feature=share
https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExMWxwaWJ6ejBweXdkMDF0bjgyMmtiOWY1djhka2NteHl6ZWNzY29qNiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/2Qb9u5uOToZK23Ua4u/giphy.gif
Video¶
You can see the result in the following video:
from machine import Pin
import time
LED = Pin(18,Pin.OUT)
LED.value(1)
time.sleep(2)
LED.value(0)
time.sleep(2)
To keep the lighting on all the time
from machine import Pin
import time
while True:
LED = Pin(18,Pin.OUT)
LED.value(0.3)
time.sleep(0.3)
LED.value(0)
time.sleep(0.3)
files¶
click to download my car model
Fan motor
import machine
import time
# Define the GPIO pin for the fan
fan_pin = machine.Pin(18, machine.Pin.OUT)
def turn_on_fan():
fan_pin.value(1)
print("Fan turned on")
def turn_off_fan():
fan_pin.value(0)
print("Fan turned off")
def control_fan():
while True:
turn_on_fan()
time.sleep(2) # Fan runs for 5 seconds
turn_off_fan()
time.sleep(1) # Fan is off for 5 seconds
if __name__ == "__main__":
try:
control_fan()
except KeyboardInterrupt:
turn_off_fan()
print("Exiting program")