Skip to content
Snippets Groups Projects
Commit 27640a73 authored by James Khan's avatar James Khan
Browse files

fixed week 6

parent f91c8d4a
No related branches found
No related tags found
No related merge requests found
Pipeline #546828 passed
# 6. Embedded Programming - to fix
TO FIX - add serial monitor, no breadboard
# 6. Embedded Programming - FIXED (to be marked)
This week I was tasked with investigating the datasheet for my microcontroller to get to know it better. And to compare it to other microcontroller architectures and document the comparison on our group page.
......@@ -77,31 +75,41 @@ I decided to use a potentiometer because I wanted to experiment with an analog i
### wiring
- I used a breadboard just to hold the potentiometer in place and more easily attach the wires to it.
- The red wire connects the potentiometer to the 5th spot on the female connection header (note: I didn't have a 6 pos header available, so I used an 8 with the first 2 positions not connected to anything). This is wired to 5V VCC pin on the SEEED board.
- The black wire connects the potentiometer to the 3rd spot on the header, which is connected to the GND of the SEEED board.
- The Blue wire connects to the 6th spot on the header, which is wired to pin 28 on the SEEED board. This is set up as our analog input pin in the porgram.
- Initially I used a breadboard just to hold the potentiometer in place and more easily attach the wires to it.
![potentiometer connected](../images/week06/week06-all.jpeg)
- However, later on I was told that using a breadboard can often introduce distortion from the signal. So I connected it directly to my board instead.
![potentiometer connected -NEW](../images/week06/week06-X1.jpeg)
![potentiometer connections](../images/week06/week06-connection.jpeg)
- The Green wire connects the potentiometer to the 5th spot on the female connection header (note: I didn't have a 6 pos header available, so I used an 8 with the first 2 positions not connected to anything). This is wired to the 5V Vcc pin on my board.
- The Orange wire connects the potentiometer to the 3rd spot on the header, which is connected to the GND of the SEEED board.
- The Blue wire connects to the 6th spot on the header, which is wired to pin 28 on the SEEED board. This is set up as our analog input pin in the porgram.
### programming
I wrote the program in the Arduino IDE and used it to porgrammed the board.
I didn't have to go through all the setup procedures for the Arduino IDE again because I alreay did them in [week 4- electronic production](https://fabacademy.org/2021/labs/vancouver/students/james-khan/assignments/week04/#testing-the-board).
I didn't have to go through all the setup procedures for the [Arduino IDE software](https://www.arduino.cc/en/software) again because I alreay did them in [week 4- electronic production](https://fabacademy.org/2021/labs/vancouver/students/james-khan/assignments/week04/#testing-the-board) using the instructions on the [Quentores Xiao RP2040 project page](https://gitlab.fabcloud.org/pub/programmers/quentorres).
### program operation
The program takes in the voltage of the potentiometer as input. The dial is turned to increase the voltage coming out of the potentiometer signal(output) terminal.
The program takes in the voltage of the potentiometer as input and uses it to control the blinking of 2 LEDs.
The dial is turned to increase or decrease the voltage coming out of the potentiometer signal(output) terminal.
As the dial is turned counterclockwize it increases the voltage signal value.
Every time the main body of the program loops the board reads the value of the voltage. The input voltage is interpreted as a value between 0 and 1023.
Every time the main body of the program loops the board reads the value of the voltage. The input voltage is interpreted as a value between 0 and 1023. Using Serial we send this value back to the Arduino IDE so we can see it change.
If the read value is between 0 and 350, the first LED blinks, while all others are off. The lower the value the faster the blinking.
This read value is used as the delay between turning the LEDs on and then off, so making them blink faster or slower.
If the read value is 350 or greater, the first LED stays on, and the 2nd LED blinks. The lower the value the faster the blinking.
### my code
Here's my code:
......@@ -110,10 +118,9 @@ Here's my code:
/*
potentiometer - output to LEDs
written 24 July 2024
Written 1 February 2025
by James Khan
for fab academy assignment embedded programming
This example code is in the public domain.
for fab academy assignment embedded programming
https://fabacademy.org/2021/labs/vancouver/students/james-khan/assignments/week06/
*/
......@@ -121,17 +128,18 @@ Here's my code:
// define constants to match the pin layout that you are attaching your potentiometer.
const int potentin = A3;
const int led1 = 26;
const int led2 = 0;
const int led3 = 1;
// setup our pins as inputs or outputs
void setup() {
// initialize analog potentin pin as an input.
pinMode(potentin, INPUT);
// setup serial monitor.
Serial.begin(9600);
// initialize digital led pins as output.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
......@@ -141,27 +149,25 @@ void loop() {
// read potentiometer value
int readvalue = analogRead(potentin);
// reset all leds to off
// send potentiometer reading to the serial monitor
Serial.println(readvalue);
// reset LEDs to off
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
if (readvalue < 350) {
delay((readvalue));
digitalWrite(led1, HIGH);
delay((readvalue));
}
if (readvalue >= 350) {
digitalWrite(led1, HIGH);
delay(readvalue);
digitalWrite(led2, HIGH);
delay(readvalue);
}
// leave the LEDs off using the readvalue as the delay
delay((readvalue));
// turn on the LEDs then leave them on using the readvalue as the delay
digitalWrite(led1, HIGH);
digitalWrite(led3, HIGH);
delay((readvalue));
}
```
[my potentiometer LED code (download)](../files/week06/week-6-embed-potentiometer.ino)
[my potentiometer LED code (download)](../files/week06/week_6_embed_potentiometer_v2.ino)
My program running on my SEEED micropocessor board:
......@@ -170,6 +176,12 @@ My program running on my SEEED micropocessor board:
[(Youtube link)](https://www.youtube.com/watch?v=W5Qx58YxCyg)
Running the program (with Serial Monitor in background):
<video width="620" height="540" controls>
<source src="https://fabacademy.org/2021/labs/vancouver/students/james-khan/files/week06/week06-vid.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
## lessons learned
- There are allot of microprocessors to pick from to use in your project. Each of them have differing strengths and weaknesses.
......
File added
/*
potentiometer - output to LEDs
Written 1 February 2025
by James Khan
for fab academy assignment embedded programming
https://fabacademy.org/2021/labs/vancouver/students/james-khan/assignments/week06/
*/
// define constants to match the pin layout that you are attaching your potentiometer.
const int potentin = A3;
const int led1 = 26;
const int led3 = 1;
// setup our pins as inputs or outputs
void setup() {
// initialize analog potentin pin as an input.
pinMode(potentin, INPUT);
// setup serial monitor.
Serial.begin(9600);
// initialize digital led pins as output.
pinMode(led1, OUTPUT);
pinMode(led3, OUTPUT);
}
// the loop function runs over and over again forever
// analog input is from 0 to 1023. 1000 translates to 1 second delay.
void loop() {
// read potentiometer value
int readvalue = analogRead(potentin);
// send potentiometer reading to the serial monitor
Serial.println(readvalue);
// reset LEDs to off
digitalWrite(led1, LOW);
digitalWrite(led3, LOW);
// leave the LEDs off using the readvalue as the delay
delay((readvalue));
// turn on the LEDs then leave them on using the readvalue as the delay
digitalWrite(led1, HIGH);
digitalWrite(led3, HIGH);
delay((readvalue));
}
docs/images/week06/week06-X1.jpeg

81.7 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment