Skip to content
Snippets Groups Projects
Commit bbe05d79 authored by Iryna Porokhovnichenko's avatar Iryna Porokhovnichenko
Browse files

Week 6 Updates

parent a8fb0941
No related branches found
No related tags found
No related merge requests found
Pipeline #508160 passed
Showing
with 156 additions and 0 deletions
src/assets/images/week6/busyResource.png

51.7 KiB

src/assets/images/week6/buttonExample.png

152 KiB

src/assets/images/week6/chooseInterpreter.png

89.1 KiB

src/assets/images/week6/copied.png

71.2 KiB

File added
src/assets/images/week6/error.png

53.5 KiB

src/assets/images/week6/error2.png

52.7 KiB

File added
src/assets/images/week6/funMoment.png

43.4 KiB

src/assets/images/week6/install.png

109 KiB

src/assets/images/week6/install2.png

119 KiB

File added
src/assets/images/week6/savingLibrary.png

87.9 KiB

src/assets/images/week6/savingLibrary2.png

76.6 KiB

src/assets/images/week6/success.png

39.1 KiB

src/assets/images/week6/thonny1.png

205 KiB

......@@ -47,7 +47,163 @@
<li>
to be continued...
</li>
<li>Updates after the PCB Board from Week 4 is finished:
<p>As the board created in Week 4. Electronics Production is finished I will use it for my further experiments.</p>
<p>Also I looked through the main code functions from the doc, here is a short description:</p>
<h4>Arduino Programming Functions Overview</h4>
<ul>
<li><strong>setup()</strong>: A function that runs once when the Arduino is powered on or reset. Used to initialize variables, pin modes, libraries, and other settings.</li>
<li><strong>loop()</strong>: A function that runs repeatedly after the <code>setup()</code> function. It contains the main logic that keeps executing until the board is turned off or reset.</li>
<li><strong>pinMode(pin, mode)</strong>: Configures a specified pin to behave as an input or output.
<ul>
<li><strong>pin:</strong> The number of the pin to configure.</li>
<li><strong>mode:</strong> Either <strong>INPUT</strong>, <strong>OUTPUT</strong>, or <strong>INPUT_PULLUP</strong>.</li>
</ul>
</li>
<li><strong>INPUT</strong>: Configures the pin as a high-impedance input, allowing it to read digital signals from external devices.</li>
<li><strong>INPUT_PULLUP</strong>: Configures the pin as an input with an internal pull-up resistor enabled, which connects the pin to 5V internally. This prevents floating inputs and allows simple button press detection without external resistors.</li>
<li><strong>OUTPUT</strong>: Configures the pin to send digital signals, allowing it to control components like LEDs, motors, or relays.</li>
<li><strong>digitalWrite(pin, value)</strong>: Sets a digital output pin to either HIGH (5V) or LOW (0V).</li>
<li><strong>digitalRead(pin)</strong>: Reads the digital value (HIGH or LOW) from a specified input pin.</li>
<li><strong>analogRead(pin)</strong>: Reads the analog value (0-1023) from a specified analog input pin, useful for sensors like potentiometers or temperature sensors.</li>
<li><strong>analogWrite(pin, value)</strong>: Outputs a PWM signal on a specified pin. The <code>value</code> ranges from 0 (0% duty cycle) to 255 (100% duty cycle), used for dimming LEDs or controlling motor speed.</li>
</ul>
<p>As it has button, I uploaded the Button example from Arduino Examples library to it, but changed pins to correspond our board.
<pre><code>
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; //the number of the LED pin </code></pre>
was changed to:
<pre><code>
const int buttonPin = D1; // the number of the pushbutton pin
const int signalPin = D2; // the number of the LED pin
</code></pre>
I also modified the pinMode() for button to use Input Pullup.
<pre><code>
const int buttonPin = D1; // the number of the pushbutton pin
const int signalPin = D2; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
pinMode(signalPin, OUTPUT); // initialize the LED pin as an output:
pinMode(buttonPin, INPUT_PULLUP); // initialize the pushbutton pin as an input:
}
void loop() {
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value:
Serial.println(buttonState); // Printing the state to the serial monitor
if (buttonState == HIGH) { // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
digitalWrite(signalPin, HIGH);
} else {
digitalWrite(signalPin, LOW);
}
delay(500);
}
</code></pre>
</p>
<p>As an external device I decided to use my RGB LED module from Week 9. Output Devices. It's an RGB Led. I will use one leg only and connect it to the
Connection header 4th pin, which corresponds to the D2 pin of the board. So when the button is pressed (value on D1 received) I will send a digital
HIGH to D2.
</p>
<div class="image-row">
<figure class="image-container">
<video controls style="width: 550px">
<source src="../assets/images/week6/rgbLedGreen.mp4" type="video/mp4">>
</video>
<figcaption>Green PIN of RGB led is turned on by button click</figcaption>
</figure>
</div>
</li>
<li>Trying MicroPython
<p>I've followed this tutorial on official Seed Studio Web Site <a href="https://wiki.seeedstudio.com/XIAO-RP2040-with-MicroPython/">Seeed Studio XIAO RP2040 with MicroPython</a></p>
<ol>
<li>Software setup - I've Downloaded and install <a href="https://thonny.org/">Thonny Editor</a></li>
<li>Opened it and setup the interpreter: Click "Tools-->Options" to open the settings. Then Chose the "Interpreter" interface and select the device as "MicroPython(Raspberry Pi Pico)"
and the port as "Try to detect prot automatically".</li>
<li>Pressing BOOT button and connecting the board I noticed that a new device in the system was recognized</li>
<li>Clicked Install or update MicroPython
<div class="image-row">
<figure class="image-container">
<img class="thumbnail" style="width: 550px;" src='../assets/images/week6/thonny1.png' alt='Thonny'>
<figcaption>Opening Thonny Editor</figcaption>
</figure>
<figure class="image-container">
<img class="thumbnail" style="width: 550px;" src='../assets/images/week6/chooseInterpreter.png' alt='interpreter'>
<figcaption>Choose interpreter</figcaption>
</figure>
</div>
<div class="image-row">
<figure class="image-container">
<img class="thumbnail" style="width: 550px;" src='../assets/images/week6/install.png' alt='interpreter'>
<figcaption>MicroPython installation</figcaption>
</figure>
<figure class="image-container">
<img class="thumbnail" style="width: 550px;" src='../assets/images/week6/install2.png' alt='interpreter'>
<figcaption>MicroPythn installation</figcaption>
</figure>
</div>
<p>Fun moment happened - when I connected the board and was searching for the interpreter console, I saw
only error that the Resource is busy. I saw sometimes similar error when I tried to download something through Arduino IDE to
the board, but the Serial Monitor was opened. I decided to check maybe it's again is the reason and yes, it was! It was fun
to see the python interpreter in the Serial Monitor of Arduino IDE. I closed the Monitor and after that everything worked like in
the tutorial.</p>
<div class="image-row">
<figure class="image-container">
<img class="thumbnail" style="width: 550px;" src='../assets/images/week6/busyResource.png' alt='interpreter'>
<figcaption>Resource is busy error</figcaption>
</figure>
<figure class="image-container">
<img class="thumbnail" style="width: 550px;" src='../assets/images/week6/funMoment.png' alt='Thonny'>
<figcaption>Fun moment - catching Python interpreter in the opened Serial Monitor</figcaption>
</figure>
</div>
</li>
<li>Tried Counter example
<div class="image-row">
<figure class="image-container">
<video controls style="width: 550px">
<source src="../assets/images/week6/counter.mp4" type="video/mp4">>
</video>
<figcaption>Counter example - switching the LED color on the near the USB port.</figcaption>
</figure>
</div>
</li>
<li>Tried RGB LED Example
<ul>
<li>Opened the <a href="https://files.seeedstudio.com/wiki/XIAO-RP2040/img/micropython/ws2812.py">WS2812.py</a>library in a new tab and
saved it to my PC.</li>
<li>Opened it in Thonny and saved on the board.
<div class="image-row">
<figure class="image-container">
<img class="thumbnail" style="width: 550px;" src='../assets/images/week6/savingLibrary.png' alt='Thonny'>
<figcaption>Opening Thonny Editor</figcaption>
</figure>
<figure class="image-container">
<img class="thumbnail" style="width: 550px;" src='../assets/images/week6/savingLibrary2.png' alt='interpreter'>
<figcaption>Choose interpreter</figcaption>
</figure>
</div>
</li>
<li>Tried the sketch with built-in LED RGB
<div class="image-row">
<figure class="image-container">
<video controls style="width: 550px">
<source src="../assets/images/week6/final.mp4" type="video/mp4">>
</video>
<figcaption>Programing built-in RGB Led with ws2812 library</figcaption>
</figure>
</div>
</li>
</ul>
</li>
</ol>
</li>
</ol>
<h3>Conclusions:</h3>
<div>This week I learned how to program microcontrollers using different options. I tried to do it before with Arduino IDE and C++ language,
and it was the first time I tried MicroPython.
</div>
</div>
</div>
</div>
......
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