You are on page 1of 37

Introduction to Living with

Pi Pico

Dr. Bugra Koku


Department of Mechanical Engineering
Middle East Technical University
A bit of history
• Once upon a time there was PIC16F84
• Used on a breadboard…
• Programming hardware was printed and
soldered by students!
•…
• Then for increased modularity and
robustness came MechaBoard sets

a. b. koku – METU ME Lectures 2


MechaBoard Set
• Composed of 8 cards:
– Main ControllerBoard using 4550
– Adjustable Regulator Card
– Motor Driver Card using L298
– RS232 Comm Card using Max232
– Connector Cards

a. b. koku – METU ME Lectures 3


MechaBoard Set

a. b. koku – METU ME Lectures 4


and then we used ARDUINO
• Widely available
• Standardized connections → many shields
• Development is no more restricted to our
efforts, World wide development
• Open hardware allows development of
new shields for our needs → easier than
Mechaboard!

a. b. koku – METU ME Lectures 5


Commonly Used Arduinos

• UNO

• MEGA 2560

• Mini

• Micro

a. b. koku – METU ME Lectures 6


Arduino Shields

a. b. koku – METU ME Lectures 7


Pico time now :)

8
Neo Mechaboard
• 2 stepper drivers
• 1 L293D
• Onboard regulator
• Breadboard friendly
• has WiFi

9
Pi Pico W pins

10
Programming Alternatives
• Very low level (not a real alternative :)
– 01101…
• Low level:
– Assembly
• High level:
– Basic
– C - what Arduino complies with
– Pascal

a. b. koku – METU ME Lectures 11


General Precautions

• Have all your equipment with you (i.e. toolbox)


• Always make sure that nothing shorts GND and +5V
• When working on the breadboard.
– Keep everything tidy.
– Believe in resistors: No led without resistors
– Make sure to keep all leads/jump wires as short as
possible.
– Pay attention to polarities of all relevant components, esp.
electrolytic capacitors:
• Their polarities are marked on their packages.

a. b. koku – METU ME Lectures 12


General Precautions

• Before powering up, double-check all connections


and voltage polarities.

• Generally Pico can be powered over USB


– if the current requirements of your circuit is higher than a USB port
can supply, use external power

• When using an external power supply:


– do not forget common ground
– prefer a regulated external power supply if needed
– make sure that the power supply is disconnected from your circuit
while making changes
– turn the power supply on after you are sure that everything is
properly set

a. b. koku – METU ME Lectures 13


General Precautions

• Turn the power supply off, modify your circuit, and


turn the supply back on.
• In case of using an external power supply with
current indicator, keep your eye on the current
indicator, and if you suspect that the circuit draws
too much current, immediately turn the supply off or
disconnect it.
• If anything smells funny, turn the power off, and try
to isolate the source. Do not be touch happy for a
while…

a. b. koku – METU ME Lectures 14


Programming a Microcontroller
PC
via a Programmer
PIC
Code compile download
*.bas Hex Code
*.c *.hex
PIC PIC
*.h
Compiler Programmer
etc.
Specific
Software

PIC Programmer RS232


Install on to the Parallel port
Application Circuit Take PIC out
USB

a. b. koku – METU ME Lectures


Programming a Microcontroller
PC
via a Programmer
PIC
Code compile download
*.bas Hex Code
*.c *.hex
PIC PIC
*.h
Compiler Programmer
etc.
Specific
Software

PIC Programmer RS232


Application Circuit Parallel port
ICSP USB

a. b. koku – METU ME Lectures


Programming Arduino via
PC
Bootloader
Arduino Code
*.ino compile download
Hex Code
*.c
*.hex
*.h Arduino
etc. Compiler
Bootloader
Download
Software

RS232
Parallel port
USB
Directly program the
ATMEL microprocessor
on the
Arduino Board
a. b. koku – METU ME Lectures
Booting the Loader
Program Memory
• By default the bootloader
Bootloader code
runs at each program start

• If there is a download
attempt from the computer
bootloader reads the new User Program
program and writes it in User
Program area

• If no download attempt is
detected, last loaded User Free Memory
Program program will be
executed.

a. b. koku – METU ME Lectures 18


uPython = Micropython

boot.py
main.py
and more…

19
boot.py or boot.txt
code.py or code.txt
and more…

https://learn.adafruit.com/circuitpython-essentials

20
Dev UIs: Thonny

https://thonny.org/

https://github.com/thonny/thonny/wiki/Linux 21
Dev UIs: MU

https://codewith.mu/en/download

22
CLI tools: ampy
You can ls, and manipulate and run files
- pip3 install adafruit-ampy

Try ls
- ampy --port /dev/ttyACM0 ls

or just type ampy for help

or as usual just read a bit, or more…

23
CLI tools: rshell
You can ls, and manipulate and run files
- pip3 install rshell

- then just type rshell and type repl or

help

or watch this video or as usual just read a bit,


or more…

24
CLI tools: good old screen
- connect via shell such as:

- screen /dev/ttyACM0 115200

- where ttyACM0 is assumed to be the Pico port

25
Quick Reminder
• Voltage across a resistor is proportional
to the current passing over this resistor.
• V = IR
• What are resistors?
• Why do we use them (then)?

• Reff In series? In parallel?


Reff = ΣRi Reff = 1/(Σ1/Ri )

a. b. koku – METU ME Lectures


Get Real with Arduino: Current Direction
5V
• What happens when PIN 16 is
High?
nothing
1 18
• What happens when PIN 16 is Low?
Sinks current
a
Micro
Controller • What happens when PIN 13 is Low?
nothing
• What happens when PIN 13 is
9 10 High?
Sources current

Check how much current your


pins can source and sink!!!
a. b. koku – METU ME Lectures
Get Real with Arduino: O/P
5V
If the IC we use can
source 20mA and
1 18 Min R1= ? sink 25mA

a
Micro
Controller

Min R2= ?
9 10

a. b. koku – METU ME Lectures


Get Real with Arduino: Add a LED

What value is the state of LED


when PIN 13 is set to High?

What value is the state of LED


when PIN 13 is set to Low?

a. b. koku – METU ME Lectures


Pay attention to the direction of the diode!!!
Get Real with Arduino: Add a LED

What value is the state of LED


when PIN 13 is set to High?

What value is the state of LED


when PIN 13 is set to Low?

a. b. koku – METU ME Lectures


Pay attention to the direction of the diode!!!
Get Real with Arduino: I/P via a Switch
5V

1 18
What value is read on PIN 13
when the button is NOT
a pressed?
Micro
Controller
What value is read on PIN 13
when the button is pressed?

9 10

a. b. koku – METU ME Lectures


Get Real with Arduino: I/P via a Switch
5V

1 18
What value is read on PIN 13
when the button is NOT
a pressed?
Micro
Controller
What value is read on PIN 13
when the button is pressed?

9 10

a. b. koku – METU ME Lectures


A Switch is Pressed, So
5V What???

Problem: Switch Bounce


V
Vs 5

0 t
Initial Finally
Connection Contact Closed

Typically 10-20ms
a. b. koku – METU ME Lectures
Debouncing
• Software solution
– When the state of the pin changes, wait
for a certain amount of time, and then if
the state remains changed, call it then,
not sooner.
• Hardware solution
– Schmitt Trigger:

a. b. koku – METU ME Lectures


Breadboards

a. b. koku – METU ME Lectures 35


A/D conversion
Quantization and sampling:

36
Communication Challenge
How to get in touch with PC with and without Wifi:

Write a simple calculator as in bugeval:


From the computer terminal, when you run it as:
picoeval ‘3+4’ ‘3/4' s
The arguments are to be send to pico, evaluated in pico and returned back
to print at least:
7
0.75

You can use the bugeval function on the course website as reference

The s at the end is communication preference, if it is s then PC and pico


talk over serial port, if w talk is over WiFi. If anything else or nothing is
given, talk defaults to s.

37

You might also like