Jupyter Notebook and CircuitPython

Today I learned that CircuitPython (from @adafruit) is available as a kernel for Jupyter Notebook so I had to try it out!

Installation on Windows 10

There is a tutorial on the Adafruit website that details how to install CircuitPython as a jupyter kernel. It uses the Anaconda distribution – which is not what I have installed on my computer. So I went a bit on my own.

Virtual Environment

First I created my virtual environment. I have a few python versions pre-installed which forces me to be explicit when choosing which version. Most people would only need to type python3

 python3.6.64 -m venv circuitpython

Preparing to activate the virtual environment:

cd circuitpython\Scripts

Activating is simple now.

activate

Installing Jupyter

Now that the virtual environment is active we need to install the Jupyter files. This process takes a bit of time but is quite painless on the user.

python -m pip install jupyter 

Installing the circuitpython kernel

Go to the Adafruit Github and download the latest circuitpython kernel release. Unless you want to experiment, it’s best to avoid the beta release and go with the latest release tag. As of the time of writing this post, it’s version 0.3.2

Scroll to the Assets section and download the zip file (or the other one if you prefer, whatever your computer can handle).

Unzip the file and place its content (a folder named circuitpython_kernel-master) into the circuitpython folder we created previously. cd into this new folder to install the kernel.

Following the Adafruit tutorial, now the two following commands are needed:

python setup.py install
python -m circuitpython_kernel.install

The following allows you to verify that all is good

jupyter kernelspec list

Installing CircuitPython on the CircuitPlaygroundExpress

If it’s not already done, CircuitPython needs to be installed on whatever board you have on hand. I happen to have a Circuit Playground Express.
Follow the tutorial to set your board into bootloader mode to transfer circuitpython.

Grab the appropriate file from Adafruit Github.  Look for the latest release and the assets for that specific release. I drop it directly onto the CPLAYBOOT drive.

Starting the Notebook

Typing jupyter notebook from my circuitpython folder will start up the kernel and launch my browser. YES! Let’s go into circuitpython_kernel-master/examples and run the CPX_Blinka notebook as per the Adafruit tutorial

Top right arrow does indicate the circuitpython kernel, and the numbers next to the cells show a successful run! ( I did a run all cells to get here)

At this point I have interactive python on my circuitplayground! Woohoo!

Advertisements

RGB Led and Raspberry Pi GPIO

Yesterday we had a little Coffee and Code with PyLadies Montreal.  I was asked to bring a couple of Pis and “something to play with”.  I brought mini breadboards and RGB leds.

After a brief explanation of the GPIO, the ladies started coding. We did get some result, but not the real thing. So before I forget how it works (cause I forget all the time now, sigh..) here’s the documentation on controlling an RGB led with the Pi’s GPIO.

First, the end result!

See? it does work!

Next, a schematic. I’m using a common anode RGB led.

Connecting an RGB led to GPIO
Connecting an RGB led to GPIO

Note that the anode is *not* the first leg, but rather the second leg. Grrr. Also, we’re not connecting the 5V to the anode as we did yesterday, but the Ground. The power will come from the pin when we set it to High. I *always* make that mistake, I don’t seem to be able to learn this for good. And that’s the main reason I didn’t become an electrical engineer. I suck at circuits.

So for future reference, here’s how a common anode RGB LED is supposed to be read.

RGB Led
RGB Led – courtesy of Adafruit

And finally the code:

MIT EdX Class done…

Another online class done ! This time with MIT and EdX.
MITx: 6.00.1x Introduction to Computer Science and Programming Using Python

Final score: 99%. Yeah, right! I got a 99% from an MIT class! Go me!

That said, the class served as a refresher of some Computer Science principles that I haven’t used in ages. Big-O Notation for one. I get it, I understand Big-O Notation, but I suck at it. I fail to properly identify which is which. I failed that concept when I was in university, and here I am 30 years later, still failing it. Sigh… Somehow, my brain blocks on this concept.

Apart from that, everything was review. It was mostly Computer Science, not even Python. I still think like a C programmer, and not a true Pythonista. And I know it. There were cases where I had to Google the proper Python way to do things, and not the C way. The class didn’t give any feedback on coding style, so I didn’t get the answers that I needed but getting access to Python code afterwards helped.

New Online Class : Data Wrangling with MongoDb

I have just finished my first MongoDb class with Mongo University, getting a B in the class (I missed the A by one point, grr…)

I thoroughly enjoyed working with MongoDb, and I want to keep those brand new shiny skills working. So I looked around and found “Data Wrangling with MongoDb” at Udacity. So I’m starting on that.

Lesson 1 is on CSV and Excel files. That’s where I’m at. Now I’m learning about XLRD. I have to read in an Excel worksheet, and figured out the date where some min and max have been reached.

Looking around the web, I discovered a site dedicated to Python/Excel. Cool! They have a tutorial too!

Clyde as a Twitter Monitor

This week, I will be presenting at PyLadies. Just a little pet project of mine.


Clyde is a lamp that we can hack. It’s Arduino-based and has some cool functionalities in the basic software. However there isn’t much space left to code anything else, if you want to keep that out-of-the-box functionality.  As Serial Communications are supported, I came up with the idea of pairing it with a Raspberry Pi, and coding the Pi instead.

Goal: Getting the Pi to monitor Twitter for specific hashtags, and control the color of Clyde’s eye based on trendiness of the target hashtags.  Three hashtags can be monitored, and mapped to R,G and B.  It’s best if the hashtags are *not* trending. Trying to follow the Superbowl was not a success, as the lamp was simply white (at max value) all the time. But it’s a good thing when you want to be notified of a non-trending hashtag.

CODE: