My CircuitPython assignments:
- Table of Contents
- LED Fade
- Servo Capacitative Touch
- CircuitPython LCD
- Photo Interrupter
- Distance Sensor
- RGB LED
- Hello vs Code
- Fancy LED
This assignment required us to initially learn to manipulate the on board RGB LED and to make the LED blink. Once we had figured out how to make the LED blink we had to make code for an LED so that it would fade in and out gradually.
This assignment served as our introduction into the new language of CircuitPython and a new board called a Metro MO Express. This coding langauge requres many different imports such as math, time, board, digitalio, neopixel to name a few. This specific assignment I learned how to use the import pulseio which is required to make the LED fade as well as manipulating the duty cycle. This website helped me better understand how to use PWM.
This code uses two wires inserted into Analog pins to control the direction of a servo, touching one spins it clockwise, and the other spins it counterclockwise. The servo would only move when the wires were touched.
Link to Abby Paquette's Original Image
The concept of capacitative touch was completely new to me so I had to rely on google and Mr. H for guidance. We also were required to download our first module, adafruit motor, onto the Metro. I initially had trouble getting the movement of the servo to be slight rather than a complete 180 degree turn per touch, but after using if statements I managed to regulate the movement of the servo.
This code uses a button and an lcd screen, and a switch, when pushing the button, a counter on the lcd screen increase by +1. Flipping the switch will decrease the counter on the screen by -1.
Link to Abby Paquette's Original Image
I had a problem with the button being held causing the button counter on the LCD to continuosly counting up or down. I had to add oldButtonState to make sure each press counted for a single +1 on the LCD. This website helped me understand how to set-up a button and switch in circuit python, along with example code showing how it's done.
This code counts the amount of time the photointerrupter has been interrupted within a given interval, posting that number on the serial monitor every 4 seconds.
Link to Abby Paquette's Original Image
The challenging part about this assignment was the time interval and including the amount of interrupts in that given interval. I solved with with photo and state to count the interrupts and start = time.time() to calculate the 4 second interval. This website explains how to use the import time module, specifically time.time().
This assignment had us wire an HCSR-04 sensor and use it as a distance sensor that changes the color of the neopixel on the Metro based on how far an object is from the sensor.
The challenge with this assignment was mapping out the parameters for the colors based on distance, initially I coded the sensor to give out three different colors for 5cm, 20cm, and 35cm. This code provides a good example of how to map a sensorValue which then allowed me to add a fade effect on the neopixel as distance from the sensor increased or decreased.
This assignment followed a lesson on classes, objects, and modules and how to use them. The assignment required us to wire two RGB LEDs and create a new library that would allow a code that was premade by the teachers to work. The code would assign different pins to the LEDs and make the LEDS shine different colors at certain times, each RGB LED was given a different color scheme (RBG1-Red, Blue, Magenta RGB2- Green, Cyan, Yellow)
Link to Abby Paquette's Original Image
Personally, I found it very difficult to understand how the classes, objects, and modules worked, so this assignment was all around quite difficult. The init function was also quite confusing, especially using it to define r, g, b, the colors themselves weren't too difficult to program. I used this website to better understand how the init function and the self instance worked.
This assignment was an introduction to Visual Studio (VS) code, which has all the same coding aspects of CircuitPython with the additional built in git. This makes committing, pushing, and pulling information to our GitHubs much easier.
Apart from learning the commands of VS Code, this assignment was fairly straight forward. One good thing to remember is to always git push at the end of working on VS Code so all of your work is saved on github, and to git pull when opening VS Code to pull any information/changes made on github, this avoids getting VS Code and github out of sync and potentially losing your work.
This assignment had us make yet another library for a pre-made code, this code required us to make six LEDs either alternate, chase, blink, or sparkle.
Each seperate command was fairly simple, all you have to do is program the order in which the LEDs turn on and off. I unfortunately stuck my wire into 5V instead of ground, but nothing was fried and the LEDs eventually worked. The Sparkle command was by far the hardest as it required import random I used this website to understand how the random module worked.