12 April, 2019

Experimenting blinking an LED with Gobot and Raspberry Pi

In the post 'Playing with Gobot on a Raspberry Pi', I got a Go program running on a Raspberry Pi. In this post, I am going to continue experimenting with different ways to use the Gobot framework to flash a LED.

Experiment - blink multiple sequences

In this experiment, I want to flash the LED three times rapidly then blink the LED continuously.

I created two functions. The first function flashes a LED rapidly three times. To accomplish this, I used a for loop and the sleep function. The second function flashed the LED every second. The 'work' variable calls the two new functions.

Here is the code

Experiment - changing brightness

Let's try something a little bit more complex. I want to be able to control the brightness of the LED. The first thing I did grab the example code (api_led_brightness) from Gobot. My first attempt at running the code failed. The code compiled and seems to run but the LED would not change brightness. It took a bit of head scratching before I remembered the Gobot documentation said something about PWM.

The Gobot documentation references pi-blaster. I found that I needed to setup pi-blaster to get the PWM working.

Once I got pi-blaster running on the Raspberry Pi, the example code from Gobot worked. I did encounter a minor weirdness. When I exit the running program, the LED goes to full brightness.

Resources



07 April, 2019

Playing with Gobot on a Raspberry Pi

A few days ago, I came across the Gobot website. Gobot is a framework written in the Go Programming Language (golang) to work with robots, drones and the Internet of Things (IoT). Gobot work on several different platforms including the Raspberry Pi. 

After grabbing a Raspberry Pi and an SD Card that I had laying around. My first step was to download DietPi and burn it to the SD Card. The 'Getting Started' page was easy to follow and had me running a lightweight version of Linux in short order. 

After digging through the Gobot documentation for a bit, I figured that I had enough knowledge to be dangerous. The rough plan is to setup a simple circuit and control that circuit with a simple go program running on a Rasberry Pi. The Gobot documentation has an example of flashing a LED using Rasberry Pi. In the past, I followed the 'Turning on an LED with your Raspberry Pi's GPIO Pins' tutorial from The PiHut with good results. 

It was time to get out some electronics parts. I grabbed a breadboard, a 330 Ohm resistor, a red LED, and a few Male-Female jumpers wires. 

I am using a Raspberry Pi 3 Model V1.2. From pin 12 on the Pi the orange jumper goes to the anode (long) leg of the LED. The cathode (short) leg goes to the resistor. The resistor is connected to the yellow jumper which is connected to pin 14 (ground) on the Pi. The following picture shows the setup. Please note that the blue and green jumper wires are not connected to anything.





My next step was to copy the example code from Gobot into a file on my computer. I changed the example code to use pin 12 and saved the change.

The Gobot documentation shows the compiler switches needed to create a binary that can run on a Rasberry Pi. I used the following.

GOARM=7 GOARCH=arm GOOS=linux go build {filename.go}

After copying the file binary to the Rasberry Pi, I ran the file using a terminal and the LED began to flash.


References




Challenging myself to learn something new

I have recently set a big challenge for myself. I want to know about Machine Learning . To add to the challenge, I am trying out usin...