Skip to content

TreeHacks/hardware_hackpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hardware_hackpack

This is is a beginners tutorial of how to use a microcontroller- specifically the Raspberry Pi Pico. It's made to be accessible for anyone, no matter your experience level! We nail down some foundations here and will have more hardware-related events at the hackathon. We hope the skills you learn from this hackpack help you get a footing in hardware hacks and come up with creative ideas of your own!

Parts:

Basic setup:

  1. Raspberry Pi Pico
  2. Micro USB cable
  3. Your computer!

To make a pico project:

  1. Servo Motor
  2. Jumper wires (male to female and male to male)
  3. IR sensor
  4. Breadboard

Setup ⚙️

  1. Download Thonny: From https://thonny.org/, click on the download button for your requisite OS that is on the top right corner of the screen.

  2. Connect the pico to your computer: You will need a micro-usb wire that connects the pico to your computer. While connecting it, you need to press down on the white bootsel button on the pico and then release it.

picobootsel

A folder should pop up titled RPI-RP2 which means that the pico has successfully been flashed to your computer.

Screenshot 2022-12-23 at 3 55 32 PM

  1. Download uf2 file: In this RPI-RP2 folder, click on the INDEX.HTM file which will redirect you to a webpage titled "Raspberry Pi Documentation". Scroll down on this page and under the "Microcontrollers" tab you will see "Micropython". Click on that.

Screenshot 2022-12-23 at 3 58 57 PM

Now, on the page about Micropython scroll down to the "Drag-and-Drop MicroPython" section under which you will see instructions to download micropython for different boards. Click on the "Raspberry Pi Pico" option and a uf2 file should begin downloading (file named something like rp2-pico-......uf2).

Screenshot 2022-12-23 at 4 01 33 PM

  1. Add file to pico: Drag and drop the file into the RPI-RP2 folder. This will cause the pico to disconnect which is what is expected to happen. Then, unplug the pico from the mac. This process of setup is only required once for setting up micropython, and you do not need to do this everytime you connect the pico to your computer.

gif_pico

Micropython on the Pico 🖥️

  1. Connect the pico: Connect the pico to your computer by simply plugging it in. Do not press the bootsel button. Furthermore, no folder will be appearing this time.

  2. Connect to Thonny: Next, open up the thonny editor we downloaded in step 1 of "Setup". Click on the bottom right tab as depicted in the image below and select "MicroPython (Raspberry Pi Pico).

Screenshot 2022-12-23 at 7 53 37 PM

  1. Hello world: Let us check if there are any errors by running a simple print statement in Thonny's shell.

thonnyimg

  1. Blink.py: Now, we run an actual program on our Pico. Open up a new file in thonny and copy-paste the contents of blink.py that is available in this repository. Click on "Save" after doing so, where you will be prompted to choose where- choose "This Computer". Save your file as "blink.py".

thonnyblink

  1. Run it: Then, click on the run button in the top tab of the Thonny editor. To stop running the program, click "stop" button that is in the same tab.

thonnyconnect

This is the result of blink.py- the onboard LED of your pico blinking periodically!

picoblink

  1. Automatically Run Code: If you wish to run this code whithout having to click the "run" button and using Thonny, you can merely rename the file to be main.py and save it to "Raspberry Pi Pico" instead of "This Computer". The Pico is always on the lookout for the main.py file and automatically runs it. Hence, whenever the pico would be connected to a power source, it would automatically run the code in its main.py.
thonnymainpy.mov

So now whenever I connect my pico to the computer, it will automatically run main.py and the led on the pico will start blinking. //video showing me connecting and disconnecting it

Congrats on running a Micropython program on your Pico!! 🎉

Now, you can experiment with different micropython programs and make your pico do cool stuff. In the next section, we go over how to further connect your pico to other objects which will allow for much more scope with what you can build!

The Pico ⚡

The pico is a microcontroller much like the arduino or adafruit's infamous m4 feather express. It has digital input and output pins (GPIO) and analog ones (ADC). These pins are what's used when we connect the pico to other objects such as sensors, motors, LEDs, etc. You can read more about the pico in its datasheet: https://datasheets.raspberrypi.com/pico/pico-datasheet.pdf

Screenshot 2022-12-25 at 12 36 18 PM

Example: IR Sensor + Servo Motor

We're going to demonstrate how to use an IR sensor in conjunction with a servo motor. Our final result is going to be a servo motor that starts when an object gets close to the sensor!

Servo

Connections:

If you've never used a breadboard before and want to know more about it, you can check out ... , (though this isn't required)
To connect the servo, follow the image below:

picoservo

The pins we have connected to are:

  1. Servo's red wire (VCC) to pico's 3V3(OUT)
  2. Servo's black wire (GND) to pico's GND
  3. Servo's orange wire (OUT) to pico's GPIO-0

The process should look something like this:

My.Movie.40.mov

Code

Follow the code in the servomotor.py file. Run the code either by saving it as main.py on the board or by running it through Thonny as we had done earlier with the 'blink' example.

Demo

Adding the Sensor

Connections:

To connect the ir sensor, follow the image below:

irpico

The pins we have connected to are:

  1. Sensor's red wire (VCC) to pico's 3V3(OUT)
  2. Sensor's black wire (GND) to pico's GND
  3. Sensor's orange wire (OUT) to pico's GPIO-21

As you can see, there are two wires that need to be connected to the pico's 3V3(OUT) pin- the servo's and the server's. For this, we connect the 3v3 pin to one of the rows in the smaller 2-row sides of the breadboard, and connect two wires in the same line! The process should look something like this:

My.Movie.41.MOV

The final connections should look something like this:

IMG_1973

Code

Follow the code in the irservo.py file. Run the code either by saving it as main.py on the board or by running it through Thonny as we had done earlier with the 'blink' example.

Demo

Note that you'll see two red lights on your IR sensor when there is an interference, and only one when there isn't!

irdemo

Conclusion

Arduino-

Adafruit M4-

Raspberry Pi Pico also supports arduino software. Circuitpython.

About HackPacks 🌲

HackPacks are built by the TreeHacks team to help hackers build great projects at our hackathon that happens every February at Stanford. We believe that everyone of every skill level can learn to make awesome things, and this is one way we help facilitate hacker culture. We open source our hackpacks (along with our internal tech) so everyone can learn from and use them! Feel free to use these at your own hackathons, workshops, and anything else that promotes building :)

If you're interested in attending TreeHacks, you can apply on our website during the application period.

You can follow us here on GitHub to see all the open source work we do (we love issues, contributions, and feedback of any kind!), and on Facebook, Twitter, and Instagram to see general updates from TreeHacks.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages