Creating Low Cost Sensor dataloggers with Python and Microcontrollers
jithin (~jithinbp) |
0
Description:
Problem Statement
Scientific experiments are heavily reliant around tools to measure physical parameters( temperature, humidity, luminosity, fields ... ) and obtain quantitative results. These recorded values then need to be visualized( Plots ) , and analyzed ( Curve fitting, fourier analysis etc ) . One might go on to also included logical operators and create closed loop controls such as adjusting a valve if air pressure in a vessel increases beyond a certain value.
Such tasks require
- Measurement equipment
- Programming Knowledge
Beginners to the field of experimentation however find several hurdles
- Expensive measurement equipment
- Proprietary platforms
- Lack of integration with your coding language of choice
Tools for the workshop
KuttyPy Plus or Arduino Nano Development boards with the KuttyPy firmware : I propose to bring these on a returnable basis. Laptops : Participants bring these
Learning Objectives of the workshop
- basic number systems essential for embedded programming
- Toggling bits in registers to make changes in the hardware (Blinking LEDs, controlling small motors etc) via Python
- Reading ADC values from the Hardware
- Plotting ADC values with Matplotlib/PyQtgraph ( A simple analog sensor such as the LM35 temperature sensor will be provided )
- We have now created our first data logger
- Analysis of recorded values
- Sine fitting using scipy to extract frequency and amplitude
- Create a simple thermostat. Temperature will be measured by the LM35/BMP180 sensor , and if/else statements control the
heater
(LEDs on the board will pretend to heat)
Sample Code
python
from kuttyPy import * #Import the library. also automatically connects to any available kuttypy hardware.
setReg('DDRD',160) #0b10100000 PD7(BLUE LED) and PD5(GREEN LED) made output type
setReg('PORTD',160) # PD5 and PD7 set to HIGH. Both LEDs start glowing. Colour looks like cyan.
Sample 2: Read data from a connected light sensor ```python from kuttyPy import * TSL2561_init() #Initialize the sensor x = TSL2561_all() #Fetch readings if x is not None: print('Total Light = %d, Infrared = %d'%(x[0],x[1]))
```
Sample 3
Using Matplotlib to plot voltage readings
The workshop outline is documented on the docs page
This is arguably the cheapest option to control and monitor real world events via Python code(assuming you already own a computer/phone) augmented by the advanced visualization and analytical abilities of Python modules.
Prerequisites:
A laptop with Python3.10
(An android phone can also be used to create portable data loggers using some of my apps on the Play store, however, it's only useful for creating visual code. Typing C code is a major pain on a small screen. compiling C is code is available via the cloud)
- If you bring your own Arduino Nano/Uno, it can be flashed with the KuttyPy bootloader, turning it into a very capable Python interfaced data logger. This can of course be done later also via your Arduino IDE.
The KuttyPy hardware based on the Atmega32 microcontroller will be provided for the workshop duration.
Video URL:
https://www.youtube.com/watch?v=AmXyuFHuhYs
Content URLs:
- https://kuttypy.readthedocs.io/en/latest/workshop/
- https://kuttypy.readthedocs.io/en/latest/workshopnano/
Speaker Info:
I'm a researcher who runs a company that manufactures scientific equipment ranging from multi purpose test and measurement equipment, to radiation detection instruments. This work is documented at my company website. I have previously spoken at various conferences such as Scipy, RMLL , Educode, and Pycon 2021, mostly on topics related to science education, and developing python powered scientific instruments.
Much of my work deals with circuit design, firmware, and software development, and contributions can be found as open source projects on my github page, the ExpEYES project, and on CSpark Research .
My academic background pertains to Physics, and I am currently engaged in Post Doctoral research on agricultural automation and biosensing, and the University has been an excellent facilitator to conduct outreach programs to train school students on modern scientific equipment.
Speaker Links:
- Previous Pycon Talk
- website I maintain(Content and work is mine) https://csparkresearch.in
- My github profile
- CSpark Github Profile (Sole contributor)
- Contributions to the ExpEYES project. github