Showing posts with label Electronics. Show all posts
Showing posts with label Electronics. Show all posts

12 May, 2019

Today on the bench, I have the HC-SR04 Ultrasonic Range Sensor connected to a Raspberry Pi 3 Model B running DietPi.



The HC-SR04 sensor has four pins (VCC, Trig, Echo, Gnd) that need to be connected to the Raspberry Pi. VCC gets connected to one of the 5v pins and Gnd (ground) gets connected to on the of the ground pins on the Rasberry Pi. This leaves Trig (Trigger) and Echo to be connected to the Rasberry Pi.

There is a minor point that needs to be considered before connecting the Trig and Echo pins to the Raspberry Pi. The GPIO headers on the Raspberry Pi can only safely handle 3.3v. The sensor is going to send the signal back using 5v. I need a way to bring 5 volts down to something under 3.3 volts. One way to do this is with a voltage divider. All I need is a couple of resistors, jumper wires, and some math. The math will be handled by the Voltage Divider Calculator. In my stock of resistors, I can see that I have a lot of 1K resistors. I will use one of those. Into the voltage divider calculator goes 5v for the voltage source, 3.3v for the output voltage, and 1K for resistance 1. The results of the calculation gave me a value of just under 2K for resistance 2.

I connected the Trig pin on the sensor to one of the open BCM pins. Now for the tricky part, I connected ground to one leg of the 2K resistor. The other leg connects to a jumper wire going to an open BCM pin on the Raspberry Pi. I then connected the Echo pin of the sensor to one leg of the 1K resistor. The other leg of the 1K resistor gets connected to the jumper wire that I connected the 2K resistor to.





This takes care of the wiring up of the sensor. Now we get to move on to writing some code.

Over in GitHub, I created a repo named go_rpi. In the devices folder, there is a file named 'hcsr04.go'. This code file contains the code for interacting with the HC-SR04 sensor. I am taking advantage of the go-rpio library from Stian Eikeland to access the GPIO-pins. The heart of the code is the 'measure' function. This function coordinates the actions for initializing the pins to a low state, triggering the pulse, capturing the time it takes the signal to go out and back, and calculating the distance.

Resources

Datasheet on HC-SR04

Voltage Divider

Blog Posts

GitHub







04 May, 2019

Using Go to read the temperature from R1820 on a Raspberry Pi running DietPi

The other day, I came across an electronic component labeled with 'RW1820'. The component is a digital temperature sensor. I figured it would fun to see if I could write a program in Go to read the value from the sensor and to display the temperature onscreen.

The Component



Wiring it Up

The little breakout board that the chip is attached to has three pins labeled 'G', 'R', and 'Y'. The 'G' pin goes to ground, the 'R' pin goes to +5V DC, and the 'Y' pin goes to Signal. In my case, the signal is pin 7 on the Raspberry Pi.


Enable 1-Wire

From what I have been able to learn the sensor uses 1-Wire for the communications.

I am running DietPi on the Raspberry Pi so I could not use the standard 'raspi-config' or the 'Raspberry Pi Configuration' in Raspbian. This left me with the option of adding

dtoverlay=w1-gpio

to the '/boot/config.txt' file. Just a quick edit of a file and I should be good to go. It turns out that on DietPi you need to edit the file '/DietPi/config.txt' in order to have the change survive a reboot.

Once dtoverlay is added to 'DietPi/config.txt' file, the Rasberry Pi will start communicating with the device. Take a look in the folder '/sys/bus/w1/devices'. One of the folders will start with '28-' that folder will contain a file name 'w1-slave' if you read the content of that file you will get something like

72 01 4b 46 7f ff 0e 10 57 : crc=57 YES
72 01 4b 46 7f ff 0e 10 57 t=23125

Notice the 't=' at near the end of the second line. This is the temperature in Celsius. This temperature is also missing a decimal point.

Go Code


Misc

The RW1820 is very similar to the DS18B20. There is a lot more information about the DS18B20. 

Resources

Rayway International - Chinese
RW1820 Datasheet - English
1-Wire
Enable 1-Wire Interface on the Raspberry Pi
DietPi
W1-GPIO - One-Wire Interface
Introduction to DS18B20

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




14 January, 2018

Printing the Stackable resistor box with labels

This week, I am trying to get a bit more organized. My current project is to better organize all electronic components that I have.

I got started by picking up a couple of HDX 15-Compartment Interlocking Small Parts Organizer in Black (2-Pack). This got most of the small components grouped together. This left with an issue. There is a fair number of resistors of different values in one compartment. This leaves me hunting and pecking through a mess to find the resistor I need.

After poking around Thingiverse, I came across a possible solution. The Stackable resistor box with labels. There two parts the case and the drawer. The case has an interlocking mechanism. Giving me a number of possibilities for connecting the boxes together and flexibility to print the number of boxes I need.

Preparing and Slicing

  • Import the two parts into the Slic3r
  • Changed the orientation of the models so supports are not needed
  • Sliced the models
  • Sent the models to the OctoPrint server.
Updates to the 3D Printer settings
  • Changed the z height. Hopefully, this will help the print release a little easier.
Results
The overall print quality is good. The case has a little stringing on the inside. There are a few minor defects with the outer surface. The drawer also printed well. It also has a few minor surface defects. 

The change in z height didn't help with the removing the models from the bed. I ended up destroying the drawer when I removed it from the bed. 

When I tried to fit the drawer in the case, they would not fit together properly. 

Changes
Increase the size of the case.
Print two or three cases at once. This should allow a layer to cool and set before the next layer starts.
Change the top/bottom fill pattern to something other than Hilbert Curve.



17 December, 2017

Basic Electronics Refresher

The other day, I signed up with Tinkercad. The site offers some neat tutorials. So far there are two main categories. The first category is 3D Design. Which offers a set of lessons for using their CAD program. The other category is Circuits. In this category, they offer a series which covers the basics of using their tool and building circuits. Their system is based on a simulator in which you build and test a circuit.

I was able to work through the first four lessons (Start Simulating, Editing Components, Wiring Components, and Adding Components) very quickly. It was a nice set of lessons that refreshed some old knowledge that I have not used in awhile.

I then moved to the next set of lessons (Introducing the Breadboard, Ohm's Law, and Series and Parallel Circuits) which are on Circuit Design. It was nice to get a small refresher on Ohm's Law. I enjoyed messing around with the Multimeter Component. I encountered a few places in the lessons where the text did not line up with what was happing on screen. The instructions about how to duplicate a component were wrong.

In digging up some more information about Tinkercad Circuits, there was Electronics Lab. Electronics Lab as moved to being part of Tinkercad Circuits. The blog post about the move can be found here. As far as I can tell Electronics Lab also used the name Autodesk Circuits. On YouTube, the Autodesk 123D channel has the playlist Autodesk Circuits.

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...