Physical Computing using Jupyter Notebook

Physical Computing using Jupyter NotebookMarcelo RovaiBlockedUnblockFollowFollowingMay 4Learn how to install Jupyter Notebook on a Raspberry Pi, and directly on it, read sensors and act on actuators.We all know that Jupyter Notebook is a fantastic tool, or better, an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text.Jupyter Notebook is largely used in Data Science, cleaning and transforming data, doing numerical simulation, statistical modeling, data visualization, machine learning, and much more!But, how about to use Jupyter Notebooks to control Raspberry Pi GPIOs?That’s is what we will do in this tutorial..We will learn how to install Jupyter Notebook on a Raspberry Pi, and directly on it, we will read sensors and act on actuators.1..The HWBill of MaterialRaspberry Pi V3DHT22 Temperature and Relative Humidity SensorDS18B20 Waterproof Temperature SensorBMP180 Barometric Pressure, Temperature and Altitude SensorLEDS (3x)Push Button (1x)Resistor 4K7 ohm (2x)Resistor 1K ohm (1x)Resistor 330 ohm (3x)Protoboard and cablesThe Electrical DiagramLet’s follow the above electrical diagram and connect all 3 sensors, buttons and LEDs to Raspberry Pi.The sensors used here in this project, are the same used on my tutorial:IoT Weather Station With RPi and ESP8266I suggest that you give a look on that tutorial, where I explain one by one, how to install the sensors and their libraries, testing them individually before running the complete program.3..Installing JupyterTo install Jupyter on your Raspberry (that will run with Python 3), open Terminal and enter with following commands:sudo pip3 install jupytersudo ipython3 kernelspec install-selfNow on your terminal, run the command:jupyter notebookAnd that’s it!!!!.The Jupyter Notebook will be running as a server on:http:localhost:8888But, this is not really important for you to know, because, automatically your default browser will be opened on that address, running a “Home Page”.To stop the server and close the “kernels” (the Jupyter notebooks), you must use [Ctrl] + [C] from your keyboard.From now one, any time that you start your Pi and want use Jupyter Notebook, just type the command “Jupyter notebook” on your terminal and keep it running all the time..Running Python Scripts on Jupyter NotebookWe are assuming that you are familiar with Jupyter Notebook..You can also use widgets to synchronize stateful and stateless information between Python and JavaScript.Here in this example, we are using widgets (“Sliders”) to on cell [12}, control in REAL TIME the state of actuators, in this case, turning on or off the LEDs. Widgets are great to add more dynamic behavior on Jupyter Notebooks.As you saw, on the code, we must run the cell [11] any time that we want an update value of sensors, but of course, a widget could also be implemented here to do it automatically, or by pressing a button, for example. I will leave it as a challenge for you! ;-)InstallationIn order to use Widgets, you must install the Ipywidgets library.. More details

Leave a Reply