bobthechemist
Posts: 12
Joined: Fri Mar 14, 2014 8:34 pm

Creating a colorimeter with Scratch

Sun Apr 24, 2016 1:34 am

I recently incorporated instrument design into my upper level college Chemistry course. I have the students build a colorimeter that can be used to determine the concentration of red food coloring in beverages. Previously, the students used a multimeter as the display, but this year I wanted to give them an idea of what it would take to interface their instrument to a computer.

It turned out that Raspberry Pi with Scratch was a perfect fit.

I've provided some commentary on my website but it is short on details. The circuit design is identical to my article published in the MagPi issue 24 (grab the Word Document from github if you'd like) and I've added a 3D printed cuvette holder to block the light (my students found that the holder needs to do a better job).

The scratch program consists of two routines, one to toggle the LED (source) on and off and one to read a measurement from the detector. Since we don't have an easy way to read analog signals on the RPi, I'm using the ideas from Adafruit on making resistor based measurements using an RC circuit. I simply converted their Python code into a Scratch code block.

My students had zero experience in programming and only one of them had ever built a circuit before. Over three lab periods, the students learned the basics of Scratch, circuit design, instrument design and developed a system to measure (reasonably correctly, as it turns out) the food coloring in beverages of their choice. I owe the efficiency of the content delivery to:
[*]The ability to create multiple identical Raspberry Pi configurations by copying the SD card
[*]The ability to "teach" programming without having to delve into syntax, formatting and punctuation
[*]The RPi version of Scratch and its ability to interact with the GPIO pins on the RPi.

Below are a few pictures, an example screenshot of the code a student designed and a sample instrument.

Image

Image

timrowledge
Posts: 1422
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island

Re: Creating a colorimeter with Scratch

Sun Apr 24, 2016 5:37 am

Thanks for that explanation Bob. I didn't know you could do that RC circuit trick! This is a really interesting expansion of Scratch into non-kids areas of teaching.

I've currently got gpio server support for a couple ( I think) of ADC chips but more would be good. I've also done the mcp2317 port expanders and several motor drivers, so I bet there's a few interesting experiments one could control. Suggestions for other useful devices are welcome.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

bobthechemist
Posts: 12
Joined: Fri Mar 14, 2014 8:34 pm

Re: Creating a colorimeter with Scratch

Sun Apr 24, 2016 11:53 am

If I can access an MCP3008 and SPI devices like mcp23S17 (I presume I can do the same things with I2C, I just haven't tried), then that covers nearly everything I would use in a teaching setting. (The other being something like an L293D, which I presume can be handled already)

My biggest issue right now is my limited experience with Scratch programming. The projects on my summer activity list include graphing data on a Cartesian coordinate system and exporting a list in CSV format.

When you say you have gpio server support for the mcp2317 and some ADCs, does that mean these projects are work in progress or are they available now? I'd be interested in exploring how far I can take education-based rapid prototyping using Scratch.

ghp
Posts: 2919
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: Creating a colorimeter with Scratch

Sun Apr 24, 2016 1:54 pm

Hello,

there are other solutions available like scratchClient, which provide access to a variety of devices including ADC and port expanders.
It runs as a separate python program together with current scratch. I have written this for a scratch physical computing course for 7th grade kids at a school here in town. It uses configuration files for the setup (gpio server uses config commands).

Regards,
Gerhard

Latest addition to the range of adapters is an arduino-adapter, which allows to use the arduino GPIO, PWM and ADC with scratch. Runs from USB connection, and with low cost NANO devices it provides a breadboard friendly base for experiments.
http://heppg.de/ikg/wordpress/?p=532

User avatar
bensimmo
Posts: 5753
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Creating a colorimeter with Scratch

Sun Apr 24, 2016 3:18 pm

If you wanted to make a mock-up curvette holder, actually quite a robust one. Then use some Lego to create a square section for the holder and the technics logo bit with the holes in fit led/photodetectors nicely.

Another expansion, if the students don't already do it, would be use tricolour LEDs and apply different voltages to get a range of colour spectra to see how the light absorption for different wavelength's compares. Of course the additional programming of scratch for the additional gpio pins.

bobthechemist
Posts: 12
Joined: Fri Mar 14, 2014 8:34 pm

Re: Creating a colorimeter with Scratch

Tue Apr 26, 2016 12:00 pm

ghp wrote: there are other solutions available like scratchClient, which provide access to a variety of devices including ADC and port expanders.
It runs as a separate python program together with current scratch. I have written this for a scratch physical computing course for 7th grade kids at a school here in town. It uses configuration files for the setup (gpio server uses config commands).
Gehrard, I am unfamiliar with scratchClient and will be on the lookout for it. How much setup do you need to do in order for the students to focus on the activity at hand? For example, I did not want to teach my students about WiFi and VNC connections, so I would come in to class early and get all of this prepared so it was transparent to the students. Can scratchClient be made transparent to the students or will its setup need to be included in any documentation I provide to them?

bobthechemist
Posts: 12
Joined: Fri Mar 14, 2014 8:34 pm

Re: Creating a colorimeter with Scratch

Tue Apr 26, 2016 12:04 pm

bensimmo wrote:If you wanted to make a mock-up curvette holder, actually quite a robust one. Then use some Lego to create a square section for the holder and the technics logo bit with the holes in fit led/photodetectors nicely.

Another expansion, if the students don't already do it, would be use tricolour LEDs and apply different voltages to get a range of colour spectra to see how the light absorption for different wavelength's compares. Of course the additional programming of scratch for the additional gpio pins.
I agree totally! There are actually a number of articles in Chemistry education journals that describe using Legos for instrument design, and I've done a more sophisticated version of this project using Legos as well. There is much joy in creating science things out of bricks....

timrowledge
Posts: 1422
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island

Re: Creating a colorimeter with Scratch

Sun May 01, 2016 5:56 am

[quote="bobthechemist"When you say you have gpio server support for the mcp2317 and some ADCs, does that mean these projects are work in progress or are they available now? [/quote]
They're working and used within the code for making HATs such as there ExplorerHAT Pro work, but not yet available 'raw'. I'm still trying to work out a way to specify such things. For example, you could quite legitimately wire up an SPI attached ADC, an i2c one, another on a port expander... how on earth can one decently control such mixes within Scratch? Ideas most welcome.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

ghp
Posts: 2919
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: Creating a colorimeter with Scratch

Sun May 01, 2016 7:28 am

How much setup do you need to do in order for the students to focus on the activity at hand?
Hello,
I use scratchClient with 7th grade kids in a school. I prepare config-xml-files in advance and in the tutorials, there is a remark on how to use it 'start scratchClient with ... python src/scratchClient.py -c ikg_adc.xml' . It is transparent for the kids, no unnecessary details during lessons. In case of trouble I only need to check if they used correct command line.
For those who need to know the details, there is a web interface for scratchClient ( localhost:8080 or 127.0.0.1:8080 which shows the current config file and allows to see the data or events from scratch to scratchClient.
Just to give you an example, here is the config file for a mcp3202-adc.
breadboard setup see http://heppg.de/ikg/wordpress/?p=134 (in german, as audience is the class in school; scratchClient doc is english).
Here the tutorial section http://www.heppg.de/ikg/box/adapter/ada ... entiometer (we use a custom adapter board in school, but the mcp3202 from this board is wired exactly like on the breadboard).

Code: Select all

<?xml version='1.0' encoding='utf-8' ?>
<config version='1.0'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="config.xsd" >
 
    <description>ADC-Values.  Output values are 0..1023.
     Button input on GPIO25 
    </description>

    <!-- =========================================================================== -->
    <adapter class='adapter.adc.ADC_MCP3202_10_Input'  name='adc_A'>
        <description>ADC-Value</description>
        
        <output_value name='adc'>
            <sensor name='adcA'/>
        </output_value>
        
        <parameter name='poll.interval' value='0.066' />
        <parameter name='spi.bus' value='0' />
        <parameter name='spi.device' value='0' />
        <parameter name='adc.channel' value='0' />
    </adapter>
    <!-- 
    <adapter class='adapter.adc.ADC_MCP3202_10_Input'  name='adc_B'>
        <description>ADC-Value</description>
        
        <output_value name='adc'>
            <sensor name='adcB'/>
        </output_value>
        
        <parameter name='poll.interval' value='0.066' />
        <parameter name='spi.bus' value='0' />
        <parameter name='spi.device' value='0' />
        <parameter name='adc.channel' value='1' />
    </adapter>
     -->
    <!-- =========================================================================== -->
    <adapter class='adapter.gpio.GpioButtonInput' name='button_s0'>
        <!-- no description, urgg -->
        <gpio port='GPIO25'>
            <default dir='IN' pull='PUD_UP'  />
            <active dir='IN' pull='PUD_UP'/>
        </gpio>
        
        <output name='button_pressed'>
            <broadcast name='s0_pressed'/>
        </output>
        <output name='button_released'>
            <broadcast name='s0_released'/>
        </output>
        
        <parameter name='poll.interval' value='0.066' />
        <parameter name='value.inverse' value='true' />
    </adapter>
</config>
This config files combines the adc, two channels with a button input. The python adapter used "adapter class='adapter.adc.ADC_MCP3202_10_Input' " is documented in scratchClient docs, it uses 10 bit resolution of this device. There is also a ADC_MCP3202_12_Input-adapter, which uses 12 bits with optional averaging filter.

scratchClient is written in python. There are quite a few people around who can make adjustments to the code if needed.

Regards,
Gerhard

Return to “Scratch”