Reader small image

You're reading from  Robotics at Home with Raspberry Pi Pico

Product typeBook
Published inMar 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781803246079
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Danny Staple
Danny Staple
author image
Danny Staple

Danny Staple builds robots and gadgets as a hobbyist, makes videos about his work with robots, and attends community events such as PiWars and Arduino Day. He has been a professional Python programmer, later moving into DevOps, since 2009, and a software engineer since 2000. He has worked with embedded systems, including embedded Linux systems, throughout the majority of his career. He has been a mentor at a local CoderDojo, where he taught how to code with Python. He has run Lego Robotics clubs with Mindstorms. He has also developed Bounce!, a visual programming language targeted at teaching code using the NodeMCU IoT platform. The robots he has built with his children include TankBot, SkittleBot (now the Pi Wars robot), ArmBot, and SpiderBot.
Read more about Danny Staple

Right arrow

What is CircuitPython?

Many microcontrollers require C/C++ or Assembler to program—for example, the popular Arduino ecosystem. However, in robotics, Python is rapidly becoming a de facto language. It is used for AI and data science and is great for rapidly trying out new ideas. Let’s examine why it is handy and, specifically, why I’ve chosen CircuitPython for this book.

Python does not require a compile step. Getting you quick feedback on your code and Python’s read-eval-print loop (REPL) allow you to start typing and experimenting with code instantly. The REPL allows you to see what works before using ideas in code that you’ll keep. Here’s a REPL session with CircuitPython:

Adafruit CircuitPython 6.2.0 on 2021-04-05; Raspberry Pi Pico with rp2040
>>> print("Hello, world!")
Hello, world!

The preceding session shows a print running in a REPL on Raspberry Pi Pico. We’ll explore how to use the REPL for some Pico experiments. It even comes with built-in assistance; however, on Pico, not all of the help is left in, for size reasons.

Python has other things that help, such as being able to directly return multiple values from a function. Python has function calls and classes like C++, but functions can be used as data, and references to them can be stored in variables. Additionally, Python has functional programming elements that allow programmers to chain tools together for processing streams of data.

Python uses exceptions to handle errors, allowing you to choose how to respond to them or observe their output, leading you directly to a problem.

MicroPython is the original port of the Python language to run on small memory devices such as microcontrollers. It has a community working on it, and CircuitPython builds on it.

In CircuitPython, Raspberry Pi Pico mounts as a USB storage device, so you can copy your code and the libraries your code uses, directly onto the Pico. This makes composing code from multiple libraries or using third parties simple. Copying code over with the correct name is enough to run that code when Raspberry Pi Pico is powered up again.

CircuitPython has a huge library of device support for Neopixel LEDs, Bluetooth, many sensors, displays, and other devices. This library not only works with Pico but runs across many CircuitPython controllers, so familiarity with these library components will be useful when you are working with other controllers.

Now that we’ve chosen a language and the controller that we will build robots with in this book, it’s time to start planning a robot!

Previous PageNext Page
You have been reading a chapter from
Robotics at Home with Raspberry Pi Pico
Published in: Mar 2023Publisher: PacktISBN-13: 9781803246079
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Danny Staple

Danny Staple builds robots and gadgets as a hobbyist, makes videos about his work with robots, and attends community events such as PiWars and Arduino Day. He has been a professional Python programmer, later moving into DevOps, since 2009, and a software engineer since 2000. He has worked with embedded systems, including embedded Linux systems, throughout the majority of his career. He has been a mentor at a local CoderDojo, where he taught how to code with Python. He has run Lego Robotics clubs with Mindstorms. He has also developed Bounce!, a visual programming language targeted at teaching code using the NodeMCU IoT platform. The robots he has built with his children include TankBot, SkittleBot (now the Pi Wars robot), ArmBot, and SpiderBot.
Read more about Danny Staple