Python Tutorials – பாடம் 15 – 4×4 Matrix Keypad Module using Raspberry Pi Pico

Raspberry Pi Pico வை பயன்படுத்தி 4×4 Matrix Keypad Module ஐ கட்டுப்படுத்துவது

Required Components

  1. 4×4 Matrix Keypad-1 no
  2. Raspberry Pi Pico board-1 no
  3. Data Cable-1 no
  4. Connecting Wires-8 no

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. 4×3 Matrix keypad 1 முதல் 8 வரை உள்ள பின்களை Raspberry Pi Pico GP1 முதல் GP8 வரை உள்ள பின்களுடன் இணைக்க வேண்டும்.
  3. Python program ஐ சரி பார்க்க வேண்டும்.
  4. மின்சுற்றை சரி பார்க்க வேண்டும்.
  5. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin
import utime

# define PINs according to cabling
# following array matches 1,2,3,4 PINs from 4x4 Keypad Matrix
col_list=[1,2,3,4]
# following array matches 5,6,7,8 PINs from 4x4 Keypad Matrix
row_list=[5,6,7,8]

# set row pins to output and change array elements from
#    int to Pin objects, all set to high
for x in range(0,4):
    row_list[x]=Pin(row_list[x], Pin.OUT)
    row_list[x].value(1)

# set columns pins to input and change array elements 
#   from int to Pin objects. We'll read user input here
for x in range(0,4):
    col_list[x] = Pin(col_list[x], Pin.IN, Pin.PULL_UP)

# Create a map between keypad buttons and chars
key_map=[["D","#","0","*"],\
         ["C","9","8","7"],\
         ["B","6","5","4"],\
         ["A","3","2","1"]]

def Keypad4x4Read(cols,rows):
  for r in rows:
    r.value(0)
    result=[cols[0].value(),cols[1].value(),cols[2].value(),cols[3].value()]
    if min(result)==0:
      key=key_map[int(rows.index(r))][int(result.index(0))]
      r.value(1) # manages key keept pressed
      return(key)
    r.value(1)

# Start the main loop
print("--- Ready to get user inputs ---")
while True:
    key=Keypad4x4Read(col_list, row_list)
    if key != None:
      print("You pressed: "+key)
      utime.sleep(0.3) # gives user enoght time to release without having double inputs

Python Tutorials – பாடம் 14 – 4×3 Matrix Keypad Module using Raspberry Pi Pico

Raspberry Pi Pico வை பயன்படுத்தி 4×3 Matrix Keypad Module ஐ கட்டுப்படுத்துவது

Required Components

  1. 4×3 Matrix Keypad-1 no
  2. Raspberry Pi Pico board-1 no
  3. Data Cable-1 no
  4. Connecting Wires-8 no

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. 4×3 Matrix keypad 1 முதல் 7 வரை உள்ள பின்களை Raspberry Pi Pico GP1 முதல் GP7 வரை உள்ள பின்களுடன் இணைக்க வேண்டும்.
  3. Python program ஐ சரி பார்க்க வேண்டும்.
  4. மின்சுற்றை சரி பார்க்க வேண்டும்.
  5. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin
import utime

# define PINs according to cabling
# following array matches 1,2,3 PINs from 3x4 Keypad Matrix
col_list=[1,2,3]
# following array matches 4,5,6,7 PINs from 3x4 Keypad Matrix
row_list=[4,5,6,7]

# set row pins to output and change array elements from
#    int to Pin objects, all set to high
for x in range(0,4):
    row_list[x]=Pin(row_list[x], Pin.OUT)
    row_list[x].value(1)

# set columns pins to input and change array elements 
#   from int to Pin objects. We'll read user input here
for x in range(0,3):
    col_list[x] = Pin(col_list[x], Pin.IN, Pin.PULL_UP)

# Create a map between keypad buttons and chars
key_map=[["#","0","*"],\
         ["9","8","7"],\
         ["6","5","4"],\
         ["3","2","1"]]

def Keypad3x4Read(cols,rows):
  for r in rows:
    r.value(0)
    result=[cols[0].value(),cols[1].value(),cols[2].value()]
    if min(result)==0:
      key=key_map[int(rows.index(r))][int(result.index(0))]
      r.value(1) # manages key keept pressed
      return(key)
    r.value(1)

# Start the main loop
print("--- Ready to get user inputs ---")
while True:
    key=Keypad3x4Read(col_list, row_list)
    if key != None:
      print("You pressed: "+key)
      utime.sleep(0.3) # gives user enoght time to release without having double inputs

Python Tutorials – பாடம் 13 – L298N Motor Driver Module using Raspberry Pi Pico

L298N Motor Driver ஐ பயன்படுத்தி 2 DC மோட்டார்களை கட்டுப்படுத்துவது

Required Components

  1. L298N Motor Driver Module-1 no
  2. Raspberry Pi Pico-1 no
  3. DC Motor(gear)-2 no
  4. 12V Battery-1 no
  5. Data Cable-1 no
  6. Connecting Wires-4 no

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. மோட்டார் Driver போர்டு உடன் +12V battery இணைக்க வேண்டும்.
  3. +12V பேட்டரி இணைப்புகளை சரியாகவும் கவனமாகவும் இணைக்க வேண்டும்.
  4. மோட்டார் Driver போர்டு ENA, IN1, IN2, IN3, IN4, ENB பின்களை Raspberry Pi Pico பின்களான GP6, GP5, GP4, GP3, GP2, GP7 உடன் இணைக்க வேண்டும்.
  5. மோட்டார் Driver போர்டு OUTPUT பின்களை DC மோட்டார் பின்களுடன் இணைக்க வேண்டும்.
  6. மோட்டார் Driver போர்டு GND ஐ Raspberry Pi Pico board GND உடன் இணைக்க வேண்டும்.
  7. Python program ஐ சரி பார்க்க வேண்டும்.
  8. மின்சுற்றை சரி பார்க்க வேண்டும்.
  9. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin
import utime
 
m1 = Pin(5, Pin.OUT)
m2 = Pin(4, Pin.OUT)
m3 = Pin(3, Pin.OUT)
m4 = Pin(2, Pin.OUT)
 
en1 = Pin(6, Pin.OUT)
en2 = Pin(7, Pin.OUT)
 
en1(1)  # motor 1 enable, set value 0 to disable
en2(1)  # motor 2 enable, set value 0 to disable
 
while True:
    #Both Motor in forward direction
    m1(1)
    m2(0)
    m3(1)
    m4(0)
    utime.sleep(1)
    #Both Motor in Reverse direction
    m1(0)
    m2(1)
    m3(0)
    m4(1)
    utime.sleep(1)
    #Both Motor in stop position
    m1(0)
    m2(0)
    m3(0)
    m4(0)
    utime.sleep(5)

Python Tutorials – பாடம் 12 – L298N Motor Driver Module using Raspberry Pi Pico

L298N Motor Driver ஐ பயன்படுத்தி 1 DC மோட்டாரை கட்டுப்படுத்துவது

Required Components

  1. L298N Motor Driver Module-1 no
  2. Raspberry Pi Pico-1 no
  3. DC Motor(gear)-2 no
  4. 12V Battery-1 no
  5. Data Cable-1 no
  6. Connecting Wires-4 no

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. மோட்டார் Driver போர்டு உடன் +12V battery இணைக்க வேண்டும்.
  3. +12V பேட்டரி இணைப்புகளை சரியாகவும் கவனமாகவும் இணைக்க வேண்டும்.
  4. மோட்டார் Driver போர்டு ENA, IN1, IN2 பின்களை Raspberry Pi Pico பின்களான GP4, GP2, GP3 உடன் இணைக்க வேண்டும்.
  5. மோட்டார் Driver போர்டு OUTPUT பின்களை DC மோட்டார் பின்களுடன் இணைக்க வேண்டும்.
  6. மோட்டார் Driver போர்டு GND ஐ Raspberry Pi Pico GND உடன் இணைக்க வேண்டும்.
  7. Python program ஐ சரி பார்க்க வேண்டும்.
  8. மின்சுற்றை சரி பார்க்க வேண்டும்.
  9. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin
import utime
 
m1 = Pin(2, Pin.OUT)
m2 = Pin(3, Pin.OUT)
 
en1 = Pin(4, Pin.OUT)
 
en1(1)  # motor 1 enable, set value 0 to disable
 
while True:
    #Both Motor in forward direction
    m1(1)
    m2(0)
    utime.sleep(1)
    #Both Motor in Reverse direction
    m1(0)
    m2(1)
    utime.sleep(1)
    #Both Motor in stop position
    m1(0)
    m2(0)
    utime.sleep(5)

Python Tutorials – பாடம் 11 – Ultrasonic Sensor Module with OLED using Raspberry Pi Pico

Ultrasonic sensor distance ஐ OLED டிஸ்ப்ளேயில் பெறுதல்

Required Components

  1. OLED Display-1 no
  2. Raspberry Pi Pico board-1 no
  3. Ultrasonic Sensor-1 no
  4. USB Cable-1 no
  5. Connecting wires-1 set

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Ultrasonic Sensor VCC மற்றும் Gnd சப்ளையை Raspberry Pi Pico VBus மற்றும் GND உடன் இணைக்க வேண்டும்.
  3. Ultrasonic sensorல் உள்ள ECHO மற்றும் TRIG பின்களை Raspberry Pi Pico வில் உள்ள GP2 மற்றும் GP3 பின்களுடன் இணைக்க வேண்டும்.
  4. OLED Display VCC, GND ஐ Raspberry Pi Pico Board 3V3 (OUT), GND உடன் இணைக்க வேண்டும்.
  5. Raspberry Pi Pico Board இன் GP16, GP17 ஐ OLED Display SCK, SDA உடன் இணைக்க வேண்டும்.
  6. Python program ஐ சரி பார்க்க வேண்டும்.
  7. மின்சுற்றை சரி பார்க்க வேண்டும்.
  8. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import utime
trigger = Pin(3, Pin.OUT)
echo = Pin(2, Pin.IN)
def ultrasonnic():
    timepassed=0
    trigger.low()
    utime.sleep_us(2)
    trigger.high()
    utime.sleep_us(5)
    trigger.low()
    while echo.value() == 0:
        signaloff = utime.ticks_us()
    while echo.value() == 1:
        signalon = utime.ticks_us()
    timepassed = signalon - signaloff
    return timepassed
WIDTH  = 128                                            # oled display width
HEIGHT = 64                                            # oled display height
i2c = I2C(0, scl=Pin(17), sda=Pin(16), freq=200000)       # Init I2C using pins GP8 & GP9 (default I2C0 pins)
print("I2C Address      : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration: "+str(i2c))                   # Display I2C config
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)                  # Init oled display
 # Clear the oled display in case it has junk on it.
oled.fill(0)
# Add some text
oled.text("CIRCUIT DIGEST",5,8)
oled.text("INTERFACING THE",5,30)
oled.text("ULTRASONNIC",28,40)
oled.text("SENSOR",50,50)
# Finally update the oled display so the image & text is displayed
oled.show()
utime.sleep(4)
while True:
    oled.fill(0)
    measured_time = ultrasonnic()     
    distance_cm = (measured_time * 0.0343) / 2
    distance_cm = round(distance_cm,2)
    oled.text("<ObjectDistance>",0,8)
    oled.text(">> "+str(distance_cm)+" cm",2,25)
    oled.show()
    utime.sleep(1)   

Python Tutorials – பாடம் 10 – OLED Display Module Using Raspberry Pi Pico

Robolabz ஐ OLED டிஸ்ப்ளேயில் பெறுதல்

Required Components

  1. OLED Display-1 no
  2. Raspberry Pi Pico board-1 no
  3. USB Cable-1 no
  4. Connecting wires-1 set

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. OLED Display VCC, GND ஐ Raspberry Pi Pico Board 3V3 (OUT), GND உடன் இணைக்க வேண்டும்.
  3. Raspberry Pi Pico Board இன் GP1, GP0 ஐ OLED Display SCK, SDA உடன் இணைக்க வேண்டும்.
  4. Python program ஐ சரி பார்க்க வேண்டும்.
  5. மின்சுற்றை சரி பார்க்க வேண்டும்.
  6. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C

i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)

oled.text("ROBOLABZ", 0, 0)
oled.show()

Python Tutorials – பாடம் 9 – Ultrasonic Sensor Module using Raspberry Pi Pico

Ultrasonic sensor ஐ Raspberry Pi Pico உதவியுடன் கட்டுப்படுத்துவது

Required Components

  1. Raspberry Pi Pico board-1 no
  2. Ultrasonic sensor-1 no
  3. Data Cable-1 no
  4. Connecting wires-1 set

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Ultrasonic sensorல் உள்ள ECHO மற்றும் TRIG பின்களை Raspberry Pi Pico வில் உள்ள GP15 மற்றும் GP14 பின்களுடன் இணைக்க வேண்டும்.
  3. Ultrasonic Sensor VCC மற்றும் Gnd சப்ளையை Raspberry Pi Pico VBus மற்றும் GND உடன் இணைக்க வேண்டும்.
  4. Python program ஐ சரி பார்க்க வேண்டும்.
  5. மின்சுற்றை சரி பார்க்க வேண்டும்.
  6. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin
import utime
trigger = Pin(14, Pin.OUT)
echo = Pin(15, Pin.IN)
def ultra():
   trigger.low()
   utime.sleep_us(2)
   trigger.high()
   utime.sleep_us(5)
   trigger.low()
   while echo.value() == 0:
       signaloff = utime.ticks_us()
   while echo.value() == 1:
       signalon = utime.ticks_us()
   timepassed = signalon - signaloff
   distance = (timepassed * 0.0343) / 2
   print ('Distance:',"{:.0f}".format(distance),'cm')
while True:
   ultra()
   utime.sleep(1)

Python Tutorials – பாடம் 8 – Humidity Sensor on Raspberry Pi Pico

Humidity Sensor ஐ Raspberry Pi Pico வை பயன்படுத்தி கட்டுப்படுத்துவது

Required Components

  1. Humidity Sensor (DHT11)-1 no
  2. Raspberry Pi Pico Board-1 no
  3. Connecting wires-1 set

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Humidity Sensor உடன் Raspberry Pi Pico GP16 ஐ இணைக்க வேண்டும்.
  3. Humidity Sensor VCC மற்றும் GND உடன் Raspberry Pi Pico 3V3 (OUT) மற்றும் GND ஐ இணைக்க வேண்டும்.
  4. Python program ஐ சரி பார்க்க வேண்டும்.
  5. மின்சுற்றை சரி பார்க்க வேண்டும்.
  6. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin
import time
from dht import DHT11, InvalidChecksum
 
sensor = DHT11(Pin(16, Pin.OUT, Pin.PULL_DOWN))
 
while True:
    temp = sensor.temperature
    humidity = sensor.humidity
    print("Temperature: {}°C   Humidity: {:.0f}% ".format(temp, humidity))
    time.sleep(2)

Python Tutorials – பாடம் 7 – LDR Sensor on Raspberry Pi Pico

Raspberry Pi Pico வை பயன்படுத்தி LDR ஐ கட்டுப்படுத்துவது

Required Components

  1. LDR Sensor-1 no
  2. Raspberry Pi Pico board-1 no
  3. Connecting wires-1 set

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Raspberry Pi Pico பின்னான GP27 ஐ LDR பின்னான D0 உடன் இணைக்க வேண்டும்.
  3. Raspberry Pi Pico பின்னான 3V3 (OUT) ஐ LDR பின்னான +5V உடன் இணைக்க வேண்டும்.
  4. Raspberry Pi Pico GND உடன் LDR GND ஐ இணைக்க வேண்டும்.
  5. Python program ஐ சரி பார்க்க வேண்டும்.
  6. மின்சுற்றை சரி பார்க்க வேண்டும்.
  7. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin
import time
 
ldr = machine.ADC(27)
 
while True:
     print(ldr.read_u16())
     time.sleep(2)

Python Tutorials – பாடம் 6 – Position Encoder sensor using Raspberry Pi Pico

Raspberry Pi Pico வை பயன்படுத்தி ஒரு position encoder ஐ அளவீடு செய்வது

Required Components

  1. Position encoder sensor-1 no
  2. Raspberry Pi Pico-1 no
  3. Connecting Wires-1set

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Position encoder sensorல் உள்ள CLK மற்றும் DT பின்களை Raspberry Pi Pico வில் உள்ள GP8 மற்றும் GP9 பின்களுடன் இணைக்க வேண்டும்.
  3. Position encoder ன் +5V மற்றும் ground சப்ளையை Raspberry Pi Pico 3V3 (OUT) மற்றும் gnd உடன் இணைக்க வேண்டும்.
  4. Python program ஐ சரி பார்க்க வேண்டும்.
  5. மின்சுற்றை சரி பார்க்க வேண்டும்.
  6. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin
import utime

DT_Pin = Pin(9, Pin.IN, Pin.PULL_UP)
CLK_Pin = Pin(8, Pin.IN, Pin.PULL_UP)
SW = Pin(2, Pin.IN, Pin.PULL_UP)

LEDs = [25,4]

#create an empty list to assing pins in pico
led_pins = []

for x in range(0,2):
    led_pins.append(Pin(LEDs[x], Pin.OUT))    

value = 0
previousValue = 1

def rotary_changed():
    
    global previousValue
    global value
    
    if previousValue != CLK_Pin.value():
        if CLK_Pin.value() == 0:
            if DT_Pin.value() == 0:
          
                value = (value - 1)%2
                print("anti-clockwise", value)
            else:
                
                value = (value + 1)%2
                print("clockwise", value)                
        previousValue = CLK_Pin.value()         
         
    if SW.value() == 0:       
        print("Button pressed")
        utime.sleep(1)
        
while True:
    for i in range(0,2):
        led_pins[i].value(0)
        rotary_changed()
        led_pins[value].value(1)
        utime.sleep(0.001)