know your colorCategoriesRaspberry Pi Pico

#10 Know Your Color Project with PicoBricks

LEDs are often used on electronic systems. Each button can have small LEDs next to each option. By making a single LED light up in different colors, it is possible to do the work of more than one LED with a single LED. LEDs working in this type are called RGB LEDs. It takes its name from the initials of the color names Red, Green, Blue. Another advantage of this LED is that it can light up in mixtures of 3 primary colors. Purple, turquoise, orange…

In this project you will learn about the randomness used in every programming language. We will prepare a enjoyable game with the RGB LED, OLED screen and button module of Picobricks.

In this project, we will create a timer alarm that adjusts for daylight using the light sensor in Picobricks.

Details and Algorithm

The game we will build in the project will be built on the user knowing the colors correctly or incorrectly. One of the colors red, green, blue and white will light up randomly on the RGB LED on Picobricks, and the name of one of these four colors will be written randomly on the OLED screen at the same time. The user must press the button of Picobricks within 1.5 seconds to use the right of reply. The game will be repeated 10 times, each repetition will get 10 points if the user presses the button when the colors match, or if the user does not press the button when they do not match. If the user presses the button even though the colors do not match, he will lose 10 points. After ten repetitions, the user’s score will be displayed on the OLED screen. If the user wishes, he may not use his right of reply by not pressing the button.

Components

1X PicoBricks

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button.

MicroPython Codes of the PicoBricks

				
					from machine import Pin, I2C, ADC, PWM  #to access the hardware on the pico
from picobricks import SSD1306_I2C  #OLED Screen Library
import utime
from picobricks import WS2812   #ws8212 library

#OLED Screen Settings
WIDTH  = 128                                            
HEIGHT = 64

sda=machine.Pin(4)
scl=machine.Pin(5)
#initialize digital pin 4 and 5 as an OUTPUT for OLED Communication

i2c=machine.I2C(0,sda=sda, scl=scl, freq=1000000)
neo = WS2812(pin_num=6, num_leds=1, brightness=0.3)#initialize digital pin 6 as an OUTPUT for NeoPixel

oled = SSD1306_I2C(128, 64, i2c)
ldr = ADC(Pin(27))#initialize digital pin 6 as an OUTPUT for NeoPixel
button = Pin(10,Pin.IN,Pin.PULL_DOWN)#initialize digital pin 10 as an INPUT for button
buzzer = PWM(Pin(20, Pin.OUT))#initialize digital pin 20 as an OUTPUT for buzzer
buzzer.freq(1000)

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
#RGB black and white color code
oled.fill(0)
oled.show()

neo.pixels_fill(BLACK)
neo.pixels_show()

if ldr.read_u16()<4000:
    wakeup = True
else:
    wakeup = False
    
while True:
    while wakeup==False:
        oled.fill(0)
        oled.show()
        oled.text("Good night",25,32)
        oled.show()
        #Show on OLED and print "Good night"
        utime.sleep(1)
        if ldr.read_u16()<4000:
            while button.value()==0:
                oled.fill(0)
                oled.show()
                oled.text("Good morning",15,32)
                oled.show()
                #Print the minutes, seconds, milliseconds and "Goog morning" values ​​to the X and Y coordinates determined on the OLED screen.
                neo.pixels_fill(WHITE)
                neo.pixels_show()
                buzzer.duty_u16(6000)
                utime.sleep(1)
                #wait for one second
                buzzer.duty_u16(0)
                utime.sleep(0.5)
                #wait for half second
                wakeup=True
            neo.pixels_fill(BLACK)
            neo.pixels_show()
    oled.fill(0)
    oled.show()
    oled.text("Have a nice day!",0,32)
    #Print the minutes, seconds, milliseconds and "Have a nice day!" values ​​to the X and Y coordinates determined on the OLED screen.
    oled.show()
    if ldr.read_u16()>40000:
        wakeup= False
        
    utime.sleep(1)
    #wait for one second
				
			

Arduino C Codes of the PicoBricks

				
					from machine import Pin, I2C
from picobricks import SSD1306_I2C
import utime
import urandom
import _thread
from picobricks import WS2812

WIDTH  = 128                                            
HEIGHT = 64                                          
sda=machine.Pin(4)
scl=machine.Pin(5)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=1000000)
ws = WS2812(pin_num=6, num_leds=1, brightness=0.3)

oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)

button = Pin(10,Pin.IN,Pin.PULL_DOWN)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)

oled.fill(0)
oled.show()

ws.pixels_fill(BLACK)
ws.pixels_show()

global button_pressed
score=0
button_pressed = False

def random_rgb():
    global ledcolor
    ledcolor=int(urandom.uniform(1,4))
    if ledcolor == 1:
        ws.pixels_fill(RED)
        ws.pixels_show()
    elif ledcolor == 2:
        ws.pixels_fill(GREEN)
        ws.pixels_show()
    elif ledcolor == 3:
        ws.pixels_fill(BLUE)
        ws.pixels_show()
    elif ledcolor == 4:
        ws.pixels_fill(WHİTE)
        ws.pixels_show()

def random_text():
    global oledtext
    oledtext=int(urandom.uniform(1,4))
    if oledtext == 1:
        oled.fill(0)
        oled.show()
        oled.text("RED",45,32)
        oled.show()
    elif oledtext == 2:
        oled.fill(0)
        oled.show()
        oled.text("GREEN",45,32)
        oled.show()
    elif oledtext == 3:
        oled.fill(0)
        oled.show()
        oled.text("BLUE",45,32)
        oled.show()
    elif oledtext == 4:
        oled.fill(0)
        oled.show()
        oled.text("WHITE",45,32)
        oled.show()

def button_reader_thread():
    while True:
        global button_pressed
        if button_pressed == False:
            if button.value() == 1:
                button_pressed = True
                global score
                global oledtext
                global ledcolor
                if ledcolor == oledtext:
                    score += 10
                else:
                    score -= 10
        utime.sleep(0.01)

_thread.start_new_thread(button_reader_thread, ())

oled.text("The Game Begins",0,10)
oled.show()
utime.sleep(2)

for i in range(10):
    for j in range (10):
        random_text()
        random_rgb()
    button_pressed=False
    utime.sleep(1.5)
    oled.fill(0)
    oled.show()
    ws.pixels_fill(BLACK)
    ws.pixels_show()
utime.sleep(1.5)
oled.fill(0)
oled.show()
oled.text("Your total score:",0,20)
oled.text(str(score), 30,40)
oled.show()
				
			

Project Image

Project Video

Project Proposal 💡

You can make the game more enjoyable by making it a little more difficult. For example, you can speed up the game by reducing the repetition time of the colors. Or, instead of losing points when the user presses the button in the wrong place, you can finish the game and start it again.

CategoriesRaspberry Pi Pico

#9 Alarm Clock Project with PicoBricks

Global warming is affecting the climate of our world worse every day. Countries take many precautions and sign agreements to reduce the effects of global warming. The use of renewable energy sources and the efficient use of energy is an issue that needs attention everywhere, from factories to our rooms. Many reasons such as keeping road and park lighting on in cities due to human error, and the use of high energy consuming lighting tools reduce energy efficiency. Many electronic and digital systems are developed and programmed by engineers to measure the light, temperature and humidity values ​​of the environment and ensure that they are used only when needed and in the right amounts.

In this project, we will create a timer alarm that adjusts for daylight using the light sensor in Picobricks.

Details and Algorithm

In this project we will make a simple alarm application. The alarm system we will design is designed to sound automatically in the morning. For this, we will use LDR sensor in the project..At night, the OLED screen will display a good night message to the user, in the morning, an alarm will sound with a buzzer sound, a good morning message will be displayed on the screen, and the RGB LED will light up in white for light notification. The user will have to press the button of Picobricks to stop the alarm. After these processes, which continue until the alarm is stopped, when the button is pressed, the buzzer and RGB LED will turn off and a good day message will be displayed on the OLED screen.

Components

1X PicoBricks

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button.

MicroPython Codes of the PicoBricks

				
					from machine import Pin, I2C, ADC, PWM  #to access the hardware on the pico
from picobricks import SSD1306_I2C  #OLED Screen Library
import utime
from picobricks import WS2812   #ws8212 library

#OLED Screen Settings
WIDTH  = 128                                            
HEIGHT = 64

sda=machine.Pin(4)
scl=machine.Pin(5)
#initialize digital pin 4 and 5 as an OUTPUT for OLED Communication

i2c=machine.I2C(0,sda=sda, scl=scl, freq=1000000)
neo = WS2812(pin_num=6, num_leds=1, brightness=0.3)#initialize digital pin 6 as an OUTPUT for NeoPixel

oled = SSD1306_I2C(128, 64, i2c)
ldr = ADC(Pin(27))#initialize digital pin 6 as an OUTPUT for NeoPixel
button = Pin(10,Pin.IN,Pin.PULL_DOWN)#initialize digital pin 10 as an INPUT for button
buzzer = PWM(Pin(20, Pin.OUT))#initialize digital pin 20 as an OUTPUT for buzzer
buzzer.freq(1000)

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
#RGB black and white color code
oled.fill(0)
oled.show()

neo.pixels_fill(BLACK)
neo.pixels_show()

if ldr.read_u16()<4000:
    wakeup = True
else:
    wakeup = False
    
while True:
    while wakeup==False:
        oled.fill(0)
        oled.show()
        oled.text("Good night",25,32)
        oled.show()
        #Show on OLED and print "Good night"
        utime.sleep(1)
        if ldr.read_u16()<4000:
            while button.value()==0:
                oled.fill(0)
                oled.show()
                oled.text("Good morning",15,32)
                oled.show()
                #Print the minutes, seconds, milliseconds and "Goog morning" values ​​to the X and Y coordinates determined on the OLED screen.
                neo.pixels_fill(WHITE)
                neo.pixels_show()
                buzzer.duty_u16(6000)
                utime.sleep(1)
                #wait for one second
                buzzer.duty_u16(0)
                utime.sleep(0.5)
                #wait for half second
                wakeup=True
            neo.pixels_fill(BLACK)
            neo.pixels_show()
    oled.fill(0)
    oled.show()
    oled.text("Have a nice day!",0,32)
    #Print the minutes, seconds, milliseconds and "Have a nice day!" values ​​to the X and Y coordinates determined on the OLED screen.
    oled.show()
    if ldr.read_u16()>40000:
        wakeup= False
        
    utime.sleep(1)
    #wait for one second
				
			

Arduino C Codes of the PicoBricks

				
					#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> 
#endif
#define PIN        6 

#define NUMPIXELS 1 
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#include <Wire.h>
#include "ACROBOTIC_SSD1306.h"
int button;
void setup() {
  // put your setup code here, to run once:
   Wire.begin();  
  oled.init();                      
  oled.clearDisplay(); 
  
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  pinMode(10,INPUT);
  pinMode(27,INPUT);
  pinMode(20,OUTPUT);
  
  pixels.begin();
  pixels.setPixelColor(0, pixels.Color(0, 0, 0));
  pixels.show();

}

void loop() {
  // put your main code here, to run repeatedly:
  oled.setTextXY(4,3);              
    oled.putString("Good night");
    
    if (analogRead(27)<200){

      while(!(button == 1)){
        
        button=digitalRead(10);
       
        oled.setTextXY(4,2);              
        oled.putString("Good morning");
        pixels.setPixelColor(0, pixels.Color(255, 255, 255));
        pixels.show();
        tone(20,494);
      }
        oled.clearDisplay();
        oled.setTextXY(4,1);              
        oled.putString("Have a nice day");
        noTone(20);
        pixels.setPixelColor(0, pixels.Color(0, 0, 0));
        pixels.show();
        delay(10000);
    }


}
				
			

Project Image

Project Video

Project Proposal 💡

You can improve the project by adding a melody as an alarm sound instead of a beep. Or, instead of an alarm set according to daylight with the LDR sensor, you can develop an alarm that sounds at the specified time, where the time information is arranged via the button and OLED screen.

CategoriesRaspberry Pi Pico

#8 My Timer Project with PicoBricks

Measuring time is a simple but important task that we do in our daily lives without realizing it. A surgeon in surgery, a business person trying to catch up with a meeting, an athlete trying to win, a student trying to finish an exam or a chess match… Smart wrist watches, phones and even professional chronometers are used to measure time. Time is a variable that should be used very accurately in electronic systems. For example, a washing machine; how long the drum will rotate clockwise, how much counterclockwise, how many seconds water must flow in order to dissolve the detergent are tasks done by measuring time. To develop projects where time is of the essence, you need to know how to use it. 

In this project, you will make your own time measuring device using PicoBricks, OLED display, button and potentiometer modules. A Timer…

Details and Algorithm

When Picobricks starts, let’s put a statement on the screen that introduces the project and contains instructions. As the user turns the potentiometer, it will set a time in the range of 0-60 minutes. When the user presses the button of Picobricks after deciding the time with the potentiometer, it will start counting down in minutes and seconds on the screen. If the button is pressed while the time is running backwards, the Timer will stop and show the remaining time on the screen. If the minute, second and second value reaches zero without pressing the button, a notification stating that the time has expired will be displayed on the screen and the program will be stopped.

Components

1X PicoBricks

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button

MicroPython Codes of the PicoBricks

				
					from machine import Pin, I2C, ADC, Timer #to acces the hardware picobricks
from picobricks import SSD1306_I2C #oled library
import utime #time library

WIDTH  = 128                                            
HEIGHT = 64
#define the width and height values

sda=machine.Pin(4)
scl=machine.Pin(5)
#we define sda ​​and scl pins for inter-path communication
i2c=machine.I2C(0,sda=sda, scl=scl, freq=1000000)#determine the frequency values

oled = SSD1306_I2C(128, 64, i2c)
pot = ADC(Pin(26))
button = Pin(10,Pin.IN,Pin.PULL_DOWN)
#determine our input and output pins

oled.fill(0)
oled.show()
#Show on OLED

time=Timer()
time2=Timer()
time3=Timer()
#define timers

def minute(timer):
    global setTimer
    setTimer -=1
    
def second(timer):
    global sec
    sec-=1
    if sec==-1:
        sec=59
        
def msecond(timer):
    global msec
    msec-=1
    if msec==-1:
        msec=99
#We determine the increments of the minute-second and millisecond values.
sec=59
msec=99

global setTimer

while button.value()==0:
    setTimer=int((pot.read_u16()*60)/65536)+1
    oled.text("Set timer:" + str(setTimer) + " min",0,12)
    oled.show()
    utime.sleep(0.1)
    oled.fill(0)
    oled.show()
#If the button is not pressed, the value determined by the potentiometer is printed on the OLED screen.
    
setTimer-=1

time.init(mode=Timer.PERIODIC,period=60000, callback=minute)
time2.init(mode=Timer.PERIODIC,period=1000, callback=second)
time3.init(mode=Timer.PERIODIC,period=10, callback=msecond)
#We determine the periods of minutes, seconds and milliseconds.
utime.sleep(0.2)#wait for 0.2 second

while button.value()==0:#burda hata var 0>>>>1 olucak çalıştıramadığım için denemedim.
    oled.text("min:" + str(setTimer),50,10)
    oled.text("sec:" + str(sec),50,20)
    oled.text("ms:" + str(msec),50,30)
    oled.show()
    utime.sleep(0.01)
    oled.fill(0)
    oled.show()
    if(setTimer==0 and sec==0 and msec==99):
        utime.sleep(0.1)
        msec=0
        break;
#When the button is pressed, it prints the min-sec-ms values ​​to the OLED screen in the determined x and y coordinates.
    
oled.text(str(setTimer),60,10)
oled.text(str(sec),60,20)
oled.text(str(msec),60,30)
oled.text("Time is Over!",10,48)
oled.show()
#Print the minutes, seconds, milliseconds and "Time is Over" values ​​to the X and Y coordinates determined on the OLED screen.
				
			

Arduino C Codes of the PicoBricks

				
					#include <Wire.h>
#include "ACROBOTIC_SSD1306.h"

int minute;
int second = 59;
int milisecond = 9;
int setTimer;

void setup() {
  // put your setup code here, to run once:
  pinMode(10,INPUT);
  pinMode(26,INPUT);

  Wire.begin();  
  oled.init();                      
  oled.clearDisplay(); 


}

void loop() {
  // put your main code here, to run repeatedly:
  oled.setTextXY(1,2);              
  oled.putString("<<My Timer>>");
  oled.setTextXY(3,1);              
  oled.putString("Please use the");
  oled.setTextXY(4,1);              
  oled.putString("Potantiometer");
  oled.setTextXY(5,0);              
  oled.putString("to set the Timer");
  delay(3000);
  oled.clearDisplay(); 
  
    while(!(digitalRead(10) == 1))
  {
    setTimer = (analogRead(26)*60)/1023;
    oled.setTextXY(3,1);              
    oled.putString("set to:");
    oled.setTextXY(3,8);              
    oled.putString(String(setTimer));
    oled.setTextXY(3,11);              
    oled.putString("min.");
  }
    oled.clearDisplay(); 
    oled.setTextXY(1,1);              
    oled.putString("The Countdown");
    oled.setTextXY(2,3);              
    oled.putString("has begin!");
    
    while(!(digitalRead(10) == 1))
  {
    milisecond = 9- (millis()%100)/10;
    second = 59-(millis()%60000)/1000;
    minute = (setTimer-1)-((millis()%360000)/60000);
    
    oled.setTextXY(5,3);              
    oled.putString(String(minute));
    oled.setTextXY(5,8);              
    oled.putString(String(second));
    oled.setTextXY(5,13);              
    oled.putString(String(milisecond));
    oled.setTextXY(5,6);              
    oled.putString(":");
    oled.setTextXY(5,11);              
    oled.putString(":");
  }
    oled.setTextXY(5,3);              
    oled.putString(String(minute));
    oled.setTextXY(5,8);              
    oled.putString(String(second));
    oled.setTextXY(5,13);              
    oled.putString(String(milisecond));
    oled.setTextXY(5,6);              
    oled.putString(":");
    oled.setTextXY(5,11);              
    oled.putString(":");
    delay(10000);

    if (minute==0 & second==0 & milisecond==0){

    oled.setTextXY(5,3);              
    oled.putString(String(minute));
    oled.setTextXY(5,8);              
    oled.putString(String(second));
    oled.setTextXY(5,13);              
    oled.putString(String(milisecond));
    oled.setTextXY(5,6);              
    oled.putString(":");
    oled.setTextXY(5,11);              
    oled.putString(":");  
    oled.putString("-finished-");
    oled.setTextXY(7,5); 
    delay(10000);
    }


}
				
			

Project Image

Project Video

Project Proposal 💡

You can add a beep to the start of the Timer. When the time is reset, you can give different and high tone warnings with the buzzer and announce that the time is up from afar.

CategoriesRaspberry Pi Pico

#7 Show Your Reaction Project with PicoBricks

Now we will prepare a game that develops attention and reflexes. Moving quickly and being able to pay attention for a long time are important developmental characteristics of children. Preschool and primary school children do activities that increase their attention span and reflexes, as they are liked by their parents and teachers. The electronic system we will prepare will be a game that increases attention and develops reflexes. After finishing the project, you can compete with your friends. 🙂 

In this project you will learn about the randomness used in every programming language. With Picobricks, we will develop an electronic system using OLED display, Button-LED and Buzzer module.

Details and Algorithm

A timer starts running as soon as the Picobricks is turned on. With this timer, we can measure 1 thousandth of a second. One thousandth of a second is called a millisecond. Timers are used in many electronic systems in daily life. Timed lighting, ovens, irons, food processors…

When our project starts working, we will display a welcome message on the OLED screen. Then we will print on the screen what the user has to do to start the game. In order to start the game, we will ask the player to prepare by counting backwards from 3 on the screen after the button is pressed. After the end of the countdown, the red LED will turn on in a random time between 2-10 seconds. We will reset the timer immediately after the red LED lights up. We will measure the timer as soon as the button is pressed again. This value we get will be in milliseconds. We will display this value on the screen as the player’s reaction time.

Components

1X PicoBricks

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button

MicroPython Codes of the PicoBricks

				
					from machine import Pin, I2C,Timer
from picobricks import SSD1306_I2C
import utime
import urandom
#define the library
WIDTH=128
HEIGHT=64
#define the width and height values
sda=machine.Pin(4)
scl=machine.Pin(5)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=2000000)
oled= SSD1306_I2C(128, 64, i2c)
button = Pin(10,Pin.IN,Pin.PULL_DOWN)
led=Pin(7,Pin.OUT)
#define our input and output pins
while True:
    led.value(0)
    oled.fill(0)
    oled.text("press the button",0,10)
    oled.text("TO START!",25,25)
    oled.show()
    #print "Press the button" and "TO START!" on the OLED screen
    while button.value()==0:
        pass
    oled.fill(0)
    oled.text("Wait For LED",15,30)
    oled.show()
    #write "wait for LED" on the screen when the button is pressed
    utime.sleep(urandom.uniform(1,5))
    led.value(1)
    timer_start=utime.ticks_ms()
    #wait for a rondom second and turn on the led
    while button.value()==0:
        pass
    timer_reaction=utime.ticks_diff(utime.ticks_ms(), timer_start)
    pressed=True
    oled.fill(0)
    oled.text("Your Time",25,25)
    oled.text(str(timer_reaction),50,50)
    oled.show()
    led.value(0)
    utime.sleep(1.5)
    #print the score and "Your Time" to the screen when the button is pressed.
				
			

Arduino C Codes of the PicoBricks

				
					#include <Wire.h>
#include "ACROBOTIC_SSD1306.h"
//define the library

int buzzer=20;
int button=10;
int led=7;
int La=440;

int old_time=0;
int now_time=0;
int score=0;
String string_score;
//define our integer and string veriables


void setup() {
  // put your setup code here, to run once:
  Wire.begin();
  oled.init();
  oled.clearDisplay();

  pinMode(led,OUTPUT);
  pinMode(buzzer,OUTPUT);
  pinMode(button,INPUT);
  Serial.begin(9600);
  //define the input and output pins

}

void loop() {
  // put your main code here, to run repeatedly:
  oled.setTextXY(3,0);
  oled.putString("Press the button");
  oled.setTextXY(5,4);
  oled.putString("TO START");

  if(digitalRead(button)==1){
    for(int i=3; i>0; i--){

      String string_i=String(i);
      oled.clearDisplay();
      oled.setTextXY(4,8);
      oled.putString(string_i);
      delay(1000);
      
    }
    //count backwards from three

    oled.clearDisplay();
    oled.setTextXY(4,6);
    oled.putString("GO!!!");
    //print "GO!!" on the OLED at x=4 y=6

    int random_wait= random(1000, 5000);
    delay(random_wait);
    //wait for a random second between 1 and 5

    digitalWrite(led, HIGH);
    old_time=millis();
    //turn on LED
    while(!(digitalRead(button)==1)){

      now_time=millis();
      score=now_time-old_time;
      string_score= String(score);
      //save score as string on button press
      
    }
    digitalWrite(led, HIGH);
    tone(buzzer, La);
    delay(200);
    noTone(buzzer);
    //turn on LED and buzzer

    oled.clearDisplay();
    oled.setTextXY(1,4);
    oled.putString("Press the");
    //print "Press the" on the OLED at x=1 Y=4

    oled.setTextXY(2,3);
    oled.putString("RESET BUTTON");
    //print "RESET BUTTON" on the OLED at X=1 Y=4

    oled.setTextXY(3,3);
    oled.putString("To Repeat!");
    //print "To Repeat!" on the OLED at X=3 Y=3

    oled.setTextXY(6,3);
    oled.putString("Score: ");
    oled.setTextXY(6,9);
    oled.putString(string_score);
    oled.setTextXY(6,13);
    oled.putString(" ms");
    Serial.println(score);
    //print score value to screen

    delay(10000);
    oled.clearDisplay();
    //wait ten seconds and clear the screen
  }

}
				
			

Project Image

Project Video

Project Proposal 💡

Picobricks needs to be reset to be able to restart the game. You can develop your project by asking the button to be pressed again to start the game again. You can also have the highest score and the last scorer printed on the screen at the end of the game.

CategoriesRaspberry Pi Pico

#6 Dominate the Rhythm Project with PicoBricks

Many events in our lives have been digitized. One of them is sounds. The tone and intensity of the sound can be processed electrically. So we can extract notes electronically. The smallest unit of sounds that make up music is called a note. Each note has a frequency and intensity. With the codes we will write, we can adjust which note should be played and how long it should last by applying frequency and intensity.

In this project, we will prepare a music system that will play the melody of a song using the buzzer module and adjust the rhythm with the potentiometer module with Picobricks. You will also learn the use of variables, which has an important place in programming terminology, in this project.

Details and Algorithm

With Picobricks you can play any song whose notes we know. We will use the button-LED module to start the song, the potentiometer module to adjust the speed of the song, and the buzzer module to play the notes.

Potentiometer is analog input module. It is variable resistance. As the amount of current flowing through it is turned, it increases and decreases like opening and closing a faucet. We will adjust the speed of the song by controlling this amount of current with codes. Buzzers change the sound levels according to the intensity of the current passing over them, and the sound tones according to the voltage frequency. With Microblock’s, we can easily code the notes we want from the buzzer module by adjusting their tones and durations.

We will check the button press status in the project. We will make the melody start playing when the button is pressed. During the playing of the melody, we will use a variable called rhythm to increase or decrease the playing times of the notes at the same rate. After Picobricks starts, we will enable the user to adjust the rhythm variable with the potentiometer, either while playing the melody or before playing it. As long as Picobricks is on, we will divide the potentiometer value (0-1023) by 128 and assign it to the rhythm variable. Variables are data structures that we use when we want to use values ​​that can be changed by the user or sensors in our codes. When the user presses the button to start the song, we will prepare the note codes that will allow the notes to play for the duration calculated according to the rhythm variable.

Components

1X PicoBricks

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button

MicroPython Codes of the PicoBricks

				
					from machine import Pin,PWM,ADC #to acces the hardware picobricks
from utime import sleep #time library

button= Pin(10,Pin.IN,Pin.PULL_DOWN)
pot=ADC(Pin(26))
buzzer= PWM(Pin(20))
#determine our input and output pins
global rithm
pressed = False

tones = {
"A3": 220,
"D4": 294,
"E4": 330,
"F4": 349
}
#define the tones

mysong = ["A3","E4","E4","E4","E4","E4","E4","F4","E4","D4","F4","E4"]#let's define the tones required for our song in the correct order into a sequence
noteTime = [1,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1]#define wait times between tones into an array

def playtone(frequency):
    buzzer.duty_u16(6000)
    buzzer.freq(frequency)
#define the frequencies of the buzzer
def playsong(pin):
    global pressed
    
    if not pressed:
        pressed = True
        for i in range(len(mysong)):
                playtone(tones[mysong[i]])
                sleep(noteTime[i]/rithm+1)
        buzzer.duty_u16(0)
#play the tones with the right cooldowns
#An finally we need to tell the pins when to trigger, and the function to call when they detect an event:       
button.irq(trigger=Pin.IRQ_RISING, handler=playsong)
while True:
    rithm= pot.read_u16()
    rithm= int(rithm/6400)+1
				
			

Arduino C Codes of the PicoBricks

				
					#include <Wire.h>
#include "ACROBOTIC_SSD1306.h"

int buzzer = 20;
int pot =26;
int button= 10;
//define the buzzer, pot and button 

int Re = 294;
int Mi = 330;
int Fa = 349;
int La = 440;
//DEFİNE THE TONES
void setup()
{
  Wire.begin();  
  oled.init();                      
  oled.clearDisplay();              

  pinMode(buzzer,OUTPUT);
  pinMode(26,INPUT);
  pinMode(button,INPUT);
//determine our input and output pins
}

void loop()
{
  int rithm = (analogRead(pot))/146;
  String char_rithm = String(rithm);
  oled.setTextXY(3,4);              
  oled.putString("Speed: ");
  oled.setTextXY(3,10);              
  oled.putString(char_rithm);
  
  //print "Speed: "  and speed value on the OLED at x=3 y=4

  delay(10); 

  if (digitalRead(button) == 1){

    oled.clearDisplay(); 
    oled.setTextXY(3,2);              
    oled.putString("Now playing...");
//print "Speed: "  and speed value on the OLED at x=3 y=4
    tone(buzzer, La); delay (1000/(rithm+1));
    tone(buzzer, Mi); delay (500/(rithm+1));
    tone(buzzer, Mi); delay (500/(rithm+1));
    tone(buzzer, Mi); delay (500/(rithm+1));
    tone(buzzer, Mi); delay (500/(rithm+1));
    tone(buzzer, Mi); delay (500/(rithm+1));
    tone(buzzer, Mi); delay (500/(rithm+1));
    tone(buzzer, Fa); delay (500/(rithm+1));
    tone(buzzer, Mi); delay (500/(rithm+1));
    tone(buzzer, Re); delay (500/(rithm+1));
    tone(buzzer, Fa); delay (500/(rithm+1));
    tone(buzzer, Mi); delay (1000/(rithm+1));
//play the notes in the correct order and time when the button is pressed

    oled.clearDisplay();
    //clear the screen
  }
  noTone(buzzer);
  //stop the buzzer
}
				
			

Project Image

Project Video

Project Proposal 💡

To make your project more visual, you can light a different color LED according to the played note, show the note names and playing speed on the OLED screen.

CategoriesRaspberry Pi Pico

#5 Graphic Monitor Project with PicoBricks

When we look at the electronic items around us, you realize that they have many replaceable features and they are designed by engineers to be most useful to the user. Such as lighting systems, cooking systems, sound systems, cleaning systems. The way it works, the amount, the method, etc., by many system users. features can be programmed to change.

In robotic projects, in the processes of changing the sound level, changing the motor speed, changing the brightness of the light, the electrical voltage is sent in a way that creates a lower or higher effect. By decreasing the frequency of the electrical signal to the component, it can be operated at a lower level, and by increasing the frequency of the outgoing electrical signals, it can be operated at a higher level.

In systems without a screen, real-time graphic monitors are used to monitor some sensors and variables involved in the operation of the system. Graphic monitors make it very easy to detect the fault.

Details and Algorithm

In this project, we will prepare a project in which we increase or decrease the brightness of the red LED with a potentiometer. In addition, we will simultaneously monitor the electrical change occurring during this process on the Microblocks graphic monitor. When the picobricks starts, the potentiometer value will be read continuously and the brightness value of the LED will be adjusted. Applications in which the effect of the electrical signal is reduced by changing the frequency is called PWM. We will send the analog values ​​we read from the potentiometer as PWM signals to the red LED and we will be able to adjust the illumination intensity.

Components

1X PicoBricks

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button

MicroPython Codes of the PicoBricks

				
					from machine import Pin,ADC,PWM
from utime import sleep
#define libraries

led=PWM(Pin(7))
pot=ADC(Pin(26,Pin.IN))
#define the value we get from the led and pot.
led.freq(1000)

while True:#while loop
    
    led.duty_u16(int((pot.read_u16())))
    print(str(int((pot.read_u16()))))
    #Turn on the LED according to the value from the potentiometer.
    
    sleep(0.1)#delay
                 
				
			

Arduino C Codes of the PicoBricks

				
					void setup() {
  // put your setup code here, to run once:
  pinMode (7,OUTPUT);//initialize digital pin 7 as an output
  pinMode (26,INPUT);//initialize digital pin 26 as an input
  Serial.begin(9600);//start serial communication


}

void loop() {
  // put your main code here, to run repeatedly:
  int pot_val = analogRead(26);
  int led_val = map(pot_val, 0, 1023, 0, 255);
  digitalWrite(7, led_val);
  Serial.println(led_val);
  //trun on the LED according to the value from the potentiometer
  
  delay(100);//wait


}
				
			

Project Image

Project Video

Project Proposal 💡

As you turn the potentiometer, you can prepare a project that changes the volume of the sound coming out of the buzzer and displays the flowing data on the graphic monitor.

CategoriesRaspberry Pi Pico

#4 Thermometer Project with PicoBricks

Sensors are the sense organs of electronic systems. We use our skin to feel, our eyes to see, our ears to hear, our tongue to taste, and our nose to smell. There are already many sense organs (sensors) in the picobrix. Also, new ones can be added. You can interact with the environment using humidity, temperature, light and many more sensors. Picobricks can measure the ambient temperature without the need for any other environmental component.

Ambient temperature is used in greenhouses, incubators, in environments used for the transport of drugs, briefly in situations where the temperature change must be constantly monitored. If you are going to do an operation on temperature change in your projects, you should know how to measure the ambient temperature. In this project, you will prepare a thermometer with Picobricks that will display the ambient temperature on the OLED screen.

Details and Algorithm

Picobricks has a DHT11 module. This module can sense the temperature and humidity in the environment and send data to the microcontroller. In this project, we will write the necessary codes to print the temperature values ​​measured by the DHT11 temperature and humidity sensor on the OLED screen.

Components

1X PicoBricks

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button

MicroPython Codes of the PicoBricks

				
					from machine import Pin,I2C,ADC #to acces the hardware picobricks
from picobricks import SSD1306_I2C, DHT11 #oled library
import utime #time library
#to acces the hardware picobricks
WIDTH=128
HEIGHT=64
#define the weight and height picobricks

sda=machine.Pin(4)
scl=machine.Pin(5)
#we define sda and scl pins for inter-path communication
i2c=machine.I2C(0, sda=sda, scl=scl, freq=2000000)#determine the frequency values
oled=SSD1306_I2C(128, 64, i2c)
pico_temp=DHT11(Pin(11))
current_time=utime.time()
while True:
    if(utime.time() - current_time > 2):
        current_time = utime.time()
        pico_temp.measure()
        oled.fill(0)#clear OLED
        oled.show()
        temperature=pico_temp.temperature
        humidity=pico_temp.humidity
        oled.text("Temperature: ",15,10)#print "Temperature: " on the OLED at x=15 y=10
        oled.text(str(int(temperature)),55,20)
        oled.text("Humidty: ", 15,40)
        oled.text(str(int(humidity)),55,50)
        oled.show()#show on OLED
        utime.sleep(0.5)#wait for a half second
				
			

Arduino C Codes of the PicoBricks

				
					#include <Wire.h>
#include <DHT.h>
#include "ACROBOTIC_SSD1306.h"
#define DHTPIN 11
#define DHTTYPE DHT11
//define the library

DHT dht(DHTPIN, DHTTYPE);
float temperature;
//define the temperature veriable

void setup() {
  //define dht sensor and Oled screen
  Serial.begin(115200);
  dht.begin();
  Wire.begin();  
  oled.init();                      
  oled.clearDisplay(); 
}

void loop() {
  temperature = dht.readTemperature();
  Serial.print("Temp: ");
  Serial.println(temperature);
  oled.setTextXY(3,1);              
  oled.putString("Temperature: ");
  //print "Temperature: " on the OLED at x=3 y=1
  oled.setTextXY(4,3);              
  oled.putString(String(temperature));
  //print the value from the temperature sensor to the oled screen at x=4 y=3
  Serial.println(temperature);
  delay(100);
}
				
			

Project Image

Project Video

Project Proposal 💡

In order to develop your project, you can make the red LED light up and a warning phrase appear on the screen when the temperature in the environment rises above 30 degrees.

CategoriesLed Raspberry Pi Pico

#3 Autonomous Lighting Project with PicoBricks

It is called the state of being autonomous when electronic systems make a decision based on the data they collect and perform the given task automatically. The components that enable electronic systems to collect data from their environment are called sensors. Many data such as the level of light in the environment, how many degrees the air temperature is, how many lt/min water flow rate, how loud the sound is, are collected by the sensors and transmitted to PicoBricks as electrical signals, that is data. There are many sensors in Picobricks. Knowing how to get data from sensors and how to interpret and use that data will improve project ideas like reading a book improves vocabulary. 

In this project, with PicoBricks, we will enable the LED to turn on when the amount of light decreases in order to understand the working systems of the systems where the lighting is turned on automatically when it gets dark.

Details and Algorithm

Sensors are electronic components that detect data in external environments and send data to microcontrollers. The LDR sensor also detects the amount of light in the environment and sends analog values. In our project, we will first check the incoming data when the environment is light and dark by reading the LDR sensor values, then we will set a limit according to these data, and if the amount of light is below this limit, we will turn off the RGB LED of Picobricks, if not, we will turn off the LED.

Components

1X PicoBricks

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button

MicroPython Codes of the PicoBricks

				
					import time
from machine import Pin, ADC
from picobricks import  WS2812
#define the library

ldr = ADC(Pin(27))
ws = WS2812(6, brightness=0.4)
#define the input and output pins

#define colors
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

COLORS = (RED, GREEN, BLUE)
#RGB color Code

while True:#while loop
    print(ldr.read_u16()) #print the value of the LDR sensor to the screen.
    
    if(ldr.read_u16()>10000):#let's check the ldr sensor
        for color in COLORS:
            
            #turn on the LDR
            ws.pixels_fill(color)
            ws.pixels_show()
                
    else:
        ws.pixels_fill((0,0,0))  #turn off the RGB
        ws.pixels_show()
				
			

Arduino C Codes of the PicoBricks

				
					#include <Adafruit_NeoPixel.h>
#define PIN            6
#define NUMLEDS        1
#define LIGHT_SENSOR_PIN 27

Adafruit_NeoPixel leds = Adafruit_NeoPixel(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);
//define the libraries

int delayval = 250; // delay for half a second

void setup() 
{
  leds.begin(); 
}

void loop() 
{
  int analogValue = analogRead(LIGHT_SENSOR_PIN);
  for(int i=0;i < NUMLEDS;i++)
  {
      if (analogValue > 200) {
          // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
          leds.setPixelColor(i, leds.Color(255,255,255));
          leds.show(); // This sends the updated pixel color to the hardware.
          delay(delayval); 
      }
       else {
         leds.setPixelColor(i, leds.Color(0,0,0));  //white color code.
         leds.show(); // This sends the updated pixel color to the hardware.
      }
    }
    delay(10);
}
				
			

Project Image

Project Video

Project Proposal 💡

In this project, we turned on the LED on the LDR sensor data on Picobricks if the environment was dark, and turned off the LED if it was bright. By processing the LDR sensor data, you can code a nightlight or table lamp in your home to turn on automatically in the dark. You can use the relay on Picobricks for this.

CategoriesLed Raspberry Pi Pico Uncategorized

#2 Action – Reaction Project with PicoBricks

As Newton explained in his laws of motion, a reaction occurs against every action. Electronic systems receive commands from users and perform their tasks. Usually a keypad, touch screen or a button is used for this job. Electronic devices respond verbally, in writing or visually to inform the user that their task is over and what is going on during the task. In addition to informing the user of these reactions, it can help to understand where the fault may be in a possible malfunction.

In this project, you will learn how to receive and react to a command from the user in your projects by coding the button-LED module of Picobricks

Details and Algorithm

Different types of buttons are used in electronic systems. Locked buttons, push buttons, switched buttons… There is 1 push button on Picobricks. They work like a switch, they conduct current when pressed and do not conduct current when released. In the project, we will understand the pressing status by checking whether the button conducts current or not. If it is pressed, it will light the LED, if it is not pressed, we will turn off the LED.

Components

1X PicoBricks

Wiring Diagram

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button

MicroPython Codes of the PicoBricks

				
					from machine import Pin#to acces the hardware picobricks
led = Pin(7,Pin.OUT)#initialize digital pin as an output for led
push_button = Pin(10,Pin.IN,Pin.PULL_DOWN)#initialize digital pin 10 as an input
while True:#while loop
    logic_state = push_button.value();#button on&off status
    if logic_state == True:#check the button and if it is on
        led.value(1)#turn on the led
    else:
        led.value(0)#turn off the led
				
			

Arduino C Codes of the PicoBricks

				
					void setup() {
  // put your setup code here, to run once:
  pinMode(7,OUTPUT);//initialize digital pin 7 as an output
  pinMode(10,INPUT);//initialize digital pin 10 as an input
  

}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(10)==1){//check the button and if it is on
    digitalWrite(7,HIGH);//turn the LED on by making the voltage HIGH
    
  }
  else{
    digitalWrite(7,LOW);//turn the LED on by making the voltage LOW 
  }
  delay(10);//wait for half second

}
				
			

Project Image

Project Video

Project Proposal 💡

In this project, the LED turns on when the button is pressed, and the LED turns off when the button is released. You can write the necessary codes for the LED to turn on when the button is pressed once and to turn the LED off when it is pressed again.

CategoriesLed Raspberry Pi Pico Uncategorized

#1 Get Started with PicoBricks – PicoBlink

In real life, the employee, who has just started to learn the job, first undertakes the most basic task.The cleaner first learns to use the broom, the cook learns to use the kitchen utensils, the waiter to carry a tray. We can increase these examples. The first code written by newcomers to software development is known as “Hello World”. Printing “Hello World” as soon as the program starts on the screen or console window in the language they use is the first step in programming. Like a baby starting to crawl… The first step to robotic c oding, also known as physical programming, is the Blink application. It means winking at robotic coding.

Details and Algorithm

There are 1 x 5mm red LED and 1 x WS2812B RGB LED on Picobricks. While normal LEDs can light up in one color, RGB colors can light up in different colors, both primary and secondary colors. In this project we will use the red LED on Picobricks.

In the project, we will write the necessary codes to turn on the red LED on Picobricks, turn it off after a certain time, turn it on again after a certain time, and repeat these processes continuously.

Components

1X PicoBricks

Wiring Diagram

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button

MicroPython Codes of the PicoBricks

				
					from machine import Pin #to access the hardware on the pico
import utime #time library
led = Pin(7,Pin.OUT)#initialize digital pin 7 as an output for LED
while True: #while loop
    led.toggle()# LED on&off status
    utime.sleep(0.5)#wait for a half second
				
			

Arduino C Codes of the PicoBricks

				
					void setup() {
  // put your setup code here, to run once:
  pinMode(7,OUTPUT);//initialize digital pin 7 as an output

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(7,HIGH);//turn the LED on by making the voltage HIGH
  delay(500);//wait for a half second
  digitalWrite(7,LOW);//turn the LED on by making the voltage LOW
  delay(500);//wait for a half second

}
				
			

Project Image

Project Video

Project Proposal 💡

Can we light the LED with different time intervals? For example; flashing of the LED several times per second, several times every half second.