Saturday, July 14, 2018

My Current Writings on the Adafruit Learning System and Blog


Where have I been writing if not on the blog? Besides writing my new book Make: Getting Started with Adafruit Circuit Playground Express, I have been writing a good number of tutorials on the Adafruit Learning System and posts on the Adafruit Blog.

What is the Adafruit Learning System? It's 1500+ free tutorials on making. With the best writers on making, electronics, and open source, the Adafruit Learning System is the place to look for inspiration for your next project.

You can find projects I have contributed to here.

Of course I have a good deal of writing on the Circuit Playground Express board - it's the easiest way to start interacting with electronics and making.

Lately my writing has focused on the new Adafruit Crickit robotics board. This not yet another robotic board (NYARB?). You certainly can make robots that look like the two wheeled bots everybody makes. But it is designed to do so much more. Do you want to use stepper motors and/or servos, check. Add NeoPixel LED lights, check. Add concurrent sound to your project, yes! So you are able to do so much more compared to previous products.

Crickit comes in two versions, one for use with Circuit Playground Express and one for Adafruit Feather  processors and boards. Adafruit has hinted of upcoming versions of Crickit for the BBC micro:bit and one for the Raspberry Pi as a HAT.

So, if you'd like to read more of my writing, please visit the Adafruit Learning System and the Adafruit blog.


New Book: Make: Getting Started with Adafruit Circuit Playground Express


My new book Make: Getting Started with Adafruit Circuit Playground Express was released earlier this month in a Humble Bundle in eBook format. The final print and eBook will be out in September, hopefully available at World Maker Faire in NYC September 22 and 23.


I should be at Maker Faire NY - stay tuned for when and where and plan to come & have fun hanging out with the Makers!

Saturday, April 14, 2018

New Company: BarelaTech, LLC

As part of my retirement and consulting, I have formed a new company: BarelaTech, LLC. Instead of me using my name, I may publish under the BarelaTech banner from time to time.
I was trying to register Unsound Engineering but the state didn't like it.

You can see the company website at https://barelatech.com/ and http://barela.tech/



Wednesday, March 28, 2018

Blogging Talk

For this month I have been taking classes in preparation of retirement from my career of nearly 30 years. They teach us a lot of skills for doing things post retirement. It's not common for an employer to provide so much preparation for retirement.

The campus, with a small snow storm moving through that lasted not even an hour.

Today was a panel discussion on writing, publishing, and blogging. The original blogger could not accommodate a revised schedule so I volunteered to talk about my experiences.

It was fun to tie in the concepts they have been teaching us in class with my experiences over the last few years.

Sunday, March 4, 2018

Book in Progress

For those following along, I write a book for Maker Media in 2014 - Getting Started with Adafruit Trinket. It has done fairly well over the years and I thank all who have bought a copy.

I was contacted 4 months ago about writing a new book on the Adafruit Circuit Playground Express. I said yes so I have been working on that since late November.

This is NOT the real cover, just a placeholder I mocked up.
I'll post more when I can, most of my free time will be writing the book.

First Career Retirement

As posted elsewhere on the Interwebs, I am retiring from my current profession as a U.S. Department of State Senior Foreign Service Officer in April 2018. I'll have exactly 30 years of service with sick leave counted in (thank you President Obama for that change to retirement).



I'll be taking a thorough retirement seminar from now through the end of April at the Foreign Service Institute at the George Schultz National Foreign Affairs Training Center (DoS FSI at NFATC for acronym lovers).

No fear for my readers of this blog. I'll be active the next day in the STEM/Maker arena. Details to come then. My writing on your favorite topics will be available.


CircuitPython Program for Writing Sensor Data to CSV File

As part of my new book, tentatively titled "Make: Getting  Started with Circuit Playground Express", one neat trick is writing sensor values to a file on the built-in flash file system. If the values are written as a text file in Comma Separated Values (CSV) format, nearly any word processor or spreadsheet program can read the file.

The Circuit Python code for reading the onboard temperature and light intensity sensors - feel free to change the readings to other sensors like the accelerometer. Name the file code.py

# Read Temperature and Light Intensity, output as a CSV file
# Mike Barela for Getting Started with Circuit Playground Express
# 2018 MIT License, attribution appreciated

import time
from adafruit_circuitplayground.express import cpx

# Set NeoPixel 0 to green as status of board, NeoPixel 1 to collecting data
cpx.pixels[0] = (0, 90, 0)  # coded red, green, blue
cpx.pixels[1] = (0, 0, 90)  # Pixel 1 blue when collecting data

num_readings = 10  # set to any finite value you want

# we try to open/create the file for append access and write the 
#    heading line. If an error occurs, go to except statement
try: 
    with open("/temp-light.csv", "a") as fp:
        fp.write('Temperature, Light Intensity\n')  # headings
        for x in range(0, num_readings):  
            temp = cpx.temperature
            # do the C-to-F conversion here if you would like
            fp.write(str(temp) + "," + str(cpx.light) + "\n")
            # Change the value of sleep time below in seconds
            # 1 minute=60 sec, 5 mins=300 sec, 1 hour=3600 sec, etc.
            time.sleep(1)
            if cpx.button_a:
                break
        # Done, set NeoPixel 1 to green also
        cpx.pixels[1] = (0, 90, 0)

except OSError as e:
    # set NeoPixel 1 off and blink NeoPixel 0 (status) depending on 
    #    the OS error
    cpx.pixels[1] = (0, 0, 0)           # Blank NeoPixel 1
    message_color = (99, 0, 0)          # Red for generic problem
    if e.args[0] == 28:                 # Device out of space
        message_color = (228, 160, 40)  # set to Orange
    elif e.args[0] == 30:               # Device is read only
        message_color = (181,  90,  0)  # set to Yellow
    for x in range(1, 10):              # Flash message 10 seconds
        cpx.pixels[0] = message_color
        time.sleep(1)
        cpx.pixels[0] = (0, 0, 0)
        time.sleep(1)
        

The filesystem normally is locked for writing unless specially set up at board boot. You can do this by placing the following file in the flash filesystem as boot.py

# boot.py
# Set Circuit Playground Express flash chip to program writeable 
#   If toggle switch is right, 
#      flash is program writeable and file access is frozen
#   If toggle switch is left,
#      flash chip file access ok, file writes give an error
# via Dan Conley 
#   https://learn.adafruit.com/cpu-temperature-logging-with-circuit-python/
#   writing-to-the-filesystem
# 2018 Mike Barela for Getting Started with Circuit Playground Express

import storage
from adafruit_circuitplayground.express import cpx

storage.remount("/", cpx.switch)

This sets the Circuit Playground Express slide switch to control if a program can write to flash or not.

Running the program without setting the slide switch to the right side results in a yellow NeoPixel.

Running the program with the slide switch on the other side the code should show a green and blue NeoPixel. When the data collection is complete, you will get two green NeoPixels. Slide the switch back, press the Reset button to reboot and open the CIRCUITPY drive on your computer file explorer. The file temp-light.csv should be there with the readings. If you run the program multiple times, it appends the results with headings on each run. With my system, I have MS Office installed and Windows correctly shows the CSV file as openable by default with Excel. You may have to expand the default column widths but otherwise the data is spot on.

More detail will be in the book out later this year. This is enough to help you if you have not got the tricks it takes to write to the filesystem.

Thanks to Dan Halbert for some Python file wizardry and Dan Conley for his tutorial on https://learn.adafruit.com.