Wednesday, August 16, 2017

Beaglebon Black PT100

Anyone who knows me knows that I love a good beer but I also enjoy making my own and I’m slowly making my home brew setup automatic.

Currently I have an all-electric brew setup with a chugger pumpheating element for my boil, and a RIM Rocket for my mash. (RIM stands for Recirculating Immersion Mash). I hooked the heating element and RIM Rocket up to a PID (Proportional, Integral, Derivative) which allows me to monitor and set the temperature of the RIM Rocket.

In order to automate a multi step mash I replaced the PID with a BBB (Beaglebone Black).  I’m hooking up a PT100 which is a three-wire, waterproof temperature probe that is currently hooked up to the PID. The reason I chose to use a BBB and not a Raspberry PI is because the PI does not have analog in/out.

Now let’s get started.
The end program and circuit is going to turn on an LED based on the temperature reading from the PT100.

What you will need:

  • PT100
  • TL317
  • 100ohm resistor
  • 0.1 micro farad capacitor
  • LED
  • 560ohm resistor

Wiring diagram:



Wiring PT100:

  • Plug P9-01 into ground of the bread board (bb).
  • Plug P9-03 into power of the bb. This is 3.3v out from BBB.
  • Plug the Capacitor from TL317 input pin to the ground of the bb.
  • Plug power from bb to the input pin of the TL317.
  • Plug the 100ohm resistor from the TL317 output pin to the TL317 adjustment pin.
  • Plug the TL317 output pin to both of the red wires from the PT100
  • Plug P9-40 to both of the red wires from the PT100. P9-40 is analog in this will be the pin we read.
  • Plug the blue wire from the PT100 to ground of the bb
  • Plug P9-34 to ground of the bb

Wiring LED:

  • Plug P9-45 to non-used ground (opposite side) of the bb
  • Plug P9-41 to non-used power (opposite side) of the bb
  • Plug One end of the LED to the ground
  • Plug the other end of the LED to the 530ohm resistor
  • Plug the other end of the resistor to the power

Program Goals:

  1. be able to read the voltage coming from the temperature gage.
  2. Figure out the voltage to temperature reading
  3. Based on the temperature turn on and off the LED

Reading Program:

I’m doing this in JS using the supplied bonescript.js library to read the pins on the BBB. The analog reader class I wrote looks like this and saved as analogRead.js:

To use the class:

Ok now we have a program that will show us the voltage readings from the PT100.

Run the program:

$: node runAnalogRead.js
mV: 1.44
Woohoo it is working.

Figure out mV to Temp formula:

Now let’s figure out the mV to Temp for a 3.3v supplied voltage.
I did this by using the the PID to set a temperature. Once the water reaches the specified temperature, take a few readings with the PT100 BBB setup, calculate the average, and then increase by 5 degrees. Repeat these steps 5 or so times. From the data gathered plot them on a graph and if it is a nice line you don’t need to do anymore readings. If not, keep repeating the steps till you have a line you like. Using that line, generate a formula where X is the mV and Y is the temp.

y = 1353.4ln(mV) - 7725.9
Note: in JS ln === log because JS log is log base e

We have our Volts-to-Temp formula. Now let’s create another .js library that will tell us the temperature at the probe:

To use this temp reading library:


Now let’s turn on that LED based on the reading:

This program will check every second to see if the temp is above 100F and if so turn the LED on.

I have to give credit to my father Ed Folz for helping the circuit for reading the PT100.

Monday, November 17, 2014

Let's make the DC Spin

Hello person reading this blog.

You will learn how to set up and control a DC motor with the BeagleBone Black RevB (BBB) and L293D IC.

Assumption

  1. You have a BBB RevB (I don't know if the stuff I say or do will work on other version)
  2. You have already setup your OS on the BBB and have it configured the way you want. I have a tut for getting a TP-Link TL-WN722N USB wireless working if you want to do wireless. 
  3. You have a basic understanding of circuits. I probably won't do circuit diagrams but you never know I might get creative. 
  4. You know Python 2.X it is different than Python 3.X
  5. You know how to run Python code on the BBB
  6. You have some type of bread board and jumper wires.
  7. You have installed the Adafruit Python Library

You will need

Your Bread Board, A L293D IC, A DC motor, 5v power supply/battery pack, and Jumper wires.

Step 1 Spin that Motor

Step 1 Wiring

Overview

In Step 1 we are simply turning on the motor. Double check your wires before you supply power to the IC. IF the motor does not start spinning once you apply power from the BBB and the 5v power supply UNPLUG EVERYTHING and double check that the wires are correct and that the power from the BB and power supply are correct. We just setup the IC's inputs to send the power to the motor to cause it to spin at full speed in one direction.

Lets try something: 
Move the orange wire from power to ground leaving it connected to pin 2 of the IC and then move the purple wire from ground to power leaving it connected to pin 7. Notice that the motor starts spinning full speed in the opposite direction.

Step 2 Control the Speed of the Motor

Step 2 Wiring


Move the Blue wire from power to P9_14.

Code:

import Adafruit_BBIO.PWM as PWM

enablePin = "P9_14"

PWM.start(enablePin, 100)

delay = 60
while int(delay) <= 100 && int(delay) >= 0:
  PWM.set_duty_cycle(enablePin, float(delay))
  delay = raw_input("Speed of Motor (0-100):")

PWM.stop(enablePin)
PWM.cleanup()

Overview

In step 1 we set the EN pin on  L293D (Pin 1) to on always. In this step we are turning it on and off using the duty cycle. From 0% to 100% speed. As you put in different numbers you will find that there is a certain point, below which your motor no longer spins. For me that happened at around 53.

Step 3 Control the Direction of the Motor

Step 3 Wiring

Changes from Step 1: Move the Purple wire from ground into P9_11, and move Orange wire from power into P9_13.

Code:

import Adafruit_BBIO.GPIO as GPIO

in1Pin = "P9_11"
in2Pin = "P9_13"

GPIO.setup(in1Pin, GPIO.OUT)
GPIO.setup(in2Pin, GPIO.OUT)

GPIO.output(in1Pin, GPIO.HIGH)
GPIO.output(in2Pin, GPIO.LOW)

rev = 60
while int(rev) == 1 || int(rev) == 0:
    rev = raw_input("Direction: 0,1")
    GPIO.output(in1Pin, int(rev) == 1)
    GPIO.output(in2Pin, int(rev) != 1)

GPIO.cleanup()

Overview

In step 2 we turned the EN switch on and off, using PWM, to control the speed of the motor. In this step we control the motors direction based on the value sent to the GPIO pins. According to the L293D documentation the two GPIO pins must be opposite for the motor to run other wise the motor is set to brake mode meaning if it was running it will do a hard stop. 

Final Step Control it ALL

Final Wiring

Changes from step 1: Move the Purple wire from Ground into P9_11, Orange wire from Power into P9_13, Blue wire from Power into P9_14.

Code:

import Adafruit_BBIO.PWM as PWM
import Adafruit_BBIO.GPIO as GPIO

enablePin = "P9_14"
in1Pin = "P9_11"
in2Pin = "P9_13"

GPIO.setup(in1Pin, GPIO.OUT)
GPIO.setup(in2Pin, GPIO.OUT)

PWM.start(enablePin, 100)

GPIO.output(in1Pin, GPIO.HIGH)
GPIO.output(in2Pin, GPIO.LOW)

delay = 60
while int(delay) <= 100 && int(delay) >= 0 && (rev == 1 || rev == 0):
  PWM.set_duty_cycle(enablePin, float(delay))
  delay = raw_input("Speed of Motor (0-100):")
  if int(delay) <= 100:
    rev = raw_input("Direction: 0,1")
    GPIO.output(in1Pin, int(rev) == 1)
    GPIO.output(in2Pin, int(rev) != 1)

PWM.stop(enablePin)
PWM.cleanup()
GPIO.cleanup()

Overview

We put what we learned from the other steps to put it all together. Now go forth and control the world one motor at a time. 

Friday, August 1, 2014

SORRY!!

I'm sorry that my blogs have been lacking lately. I am currently in the process of Moving across the country. Once I get to my new place and life allows for free time again the blogs will start again. So until then. Learn Something new.

Monday, July 7, 2014

Learning Angular

Opening:

I keep hearing how awesome this AngularJS (Angular) is. Thus, I will walk through a tutorial and make a webpage with Angular to see what I think.

What is AngularJS:

Angular is a Model View Whatever (MVW) Framework meaning it has a data structure in the background which feeds the view with the data to display to the user, allowing you to update the page and post the updated data easier.

My initial thoughts:

First thoughts of Angular after reading https://angularjs.org/ are this Javascript (JS) plug-in will make life easier in dealing with dynamic webpages by allowing me to have a model view controller (MVC) on the client side. This way I don't have to worry about how to handle the data given to me from the server I can focus on how to display and manipulate the data for the user.

The meat:

Alrighty, let's get started YEAH. docs.angularjs.org/tutorial this is the official Angular tutorial location. It is where I learned how to use Angular. What I've learned from the tutorial:

  • Angular has some really cool features built in.
  • Angular expects you to follow a certain design and implementation path. It allows you to do things a different way but it makes life hard if you try.
  • Doing Test Driven Development (TDD) with Angular is simple and suggested.
  • The Angular community is active and alive (they're not robots).

After going through the tutorial I decided to make a website that would allow me to rate drinks. The layout is pretty simple. It will have a form that will allow me to put in the name of the drink, give it a rating via stars, and then a description of the drink. It will display a list of the drinks I have rated with X amount of characters from the description as a snippet. When you click on the rating or name of drink it will take you to a page that has the full description. It also allows the list to be filtered. Here is the page I made Drink Rating

The page has 2 Angular plug-ins that allow me to add in the rating with stars and also to do local storage (no db). Since both plug-ins followed the Angular design there was no fancy do this or do that to make them work. To set up the local storage plug-in with Angular, I simply including the JS file and referencing the local storage variable in the angular controller. With the rating plug-in I added code to the view so the plug-in would know where to store the data and how to display it.

The one big downside I have seen with Angular, which could also be a big down-side for you depending on how you intend to use Angular, is that Angular is strict on its usage and how the data flows. IF you have an existing project you will have a hard time adding it to that project. Another issue is Angular no longer supports IE8. These two issues will limit my use of Angular in my world since most people want support for IE8 still and/or already have an existing project.

Conclusion - I would only use Angular if I was creating a new app focusing on 'new' browsers. I do know that you can get Angular to work with IE8 or IE7 but who really wants to do that?

In the end pro and con List:

PRO:

  • Large community for support and tools
  • Makes handling Client side easy and dynamic. 
  • The time spent spinning up a site that needs to be dynamic is GREATLY reduced
  • It is designed with TDD in mind

CON:

  • Can't easily add it to an exciting site
  • Does not support some older browsers (granted they are OLD IE browsers) 

The END:

I found that after playing around and using Angular I was able to easily create, manipulate and show data. It has traditionally been a pain to do that on the client and it added a nice layer of structure. Being designed with TDD in mind makes it worth putting the effort to do TDD. If I am able to use Angular in future projects I will. Once you use Angular you will see the light at the end of the Angular tunnel, I promise.

Monday, June 23, 2014

Lets Control a Servo

HELLO WORLD


Well hello there. In this tutorial I will be walking you through the process of controlling a continuous servo. How you control a continuous servo and a regular servo are the same.

Assumption


  1. You have a BBB RevB (I don't know if the stuff I say or do will work on other version)
  2. You have already setup your OS on the BBB and have it configured the way you want. I have a tut for getting a TP-Link TL-WN722N USB wireless working if you want to do wireless. 
  3. You have a basic understanding of circuits. I probably won't do circuit diagrams but you never know I might get creative. 
  4. You know Python 2.X it is different than Python 3.X
  5. You have some type of bread board and jumper wires.
  6. You have installed the Adafruit Python Library

You will need

Your Bread Board, the Servos, 2 1 kΩ Resistor, 5v power supply, and Bread Board Jumper wires.

Wiring


Connect the 5v power supply (upper right corner of picture) to the bread board's (bb) positive (red) and negative (blue/black).
Do once for each servo: 
  • Connect the servo's positive (red) to the bb's positive (red).
  • Connect the servo's negative (black) to bb's negative (black).
  • Connect the servo's control wire (Yellow) to one side of the bb
Put the 1kΩ Resistor in the middle of the 2 section of the bb to join them
Connect "P9_14" to one resistor and "P9_21" to the other.
Connect the Ground from the BBB to the negative (blue) of the bb and then run another wire across the bb so that you connect the ground of the BBB the the ground of the 5v power supply to complete the circuit.

The reason for the resistor is to make sure that the servo does not exceed the 250mA current that the BBB can handle.


Python Servo Code



import Adafruit_BBIO.PWM as PWM

servo_pin = "P9_14"
servo_pin2 = "P9_21"
Above we are importing the Adafruit library and setting up global variables the pins we are going to use.


PWM.start(servo_pin, (100), 60.0)
PWM.start(servo_pin2, (100), 60.0)
Now we setup the BBB so it knows which pins to us and that those pins are going to be used as PWMs. We are using the PWM.start method. This functions will take 4 parameters: channel, duty, frequency and polarity. The last 2 parameters frequency and polarity have default values thus are not required. The defaults are 2000 for frequency and polarity's is 0. Most servo's work with 50 and/or 60 Hz so I set the frequency to 60 Hz.
The first 2 parameters are required. The first one is the pin to be setup so 'P9_21' and 'P9_14'. The second one is the duty cycle of the pulse. The duty cycle is how long the pulse will be active. In this case we are setting it to 100 duty cycles which for my continuous servo means DON'T MOVE.


Note there are only 8 PWM pins P9_14, P9_16, P9_21, P9_22, P9_28, P9_29, P9_31, P9_42, P8_13, P8_19, P8_34, P8_36, P8_45, and P8_46 on a BBB RevB


PWM.set_duty_cycle(servo_pin, 0)
PWM.set_duty_cycle(servo_pin2, 0)
After we get it all setup we can change the direction and speed of the servo by using the method set_duty_cycle. It takes in the pin you want to change and the new duty cycle. By setting it to 0 the servo will now move clockwise at full speed. You can play around with your servo(s) to see what different duty_cycle values do on your servo.

Now the final code
import Adafruit_BBIO.PWM as PWM

servo_pin = "P9_14"
servo_pin2 = "P9_21"

PWM.start(servo_pin, (100), 60.0)
PWM.start(servo_pin2, (100), 60.0)

while True:
    speed1 = raw_input("Angle (0 to 100 x to exit):")
    speed2 = raw_input("Angle (0 to 100 x to exit):")
    if speed1 == 'x' or speed2 == 'x':
        PWM.stop(servo_pin)
        PWM.stop(servo_pin2)
        PWM.cleanup()
        break
    speed_f1 = float(speed1)
    speed_f2 = float(speed2)
    duty1 = 100 - speed_f1
    duty2 = 100 - speed_f2
    PWM.set_duty_cycle(servo_pin, duty1)
    PWM.set_duty_cycle(servo_pin2, duty2)

THE END.

Friday, June 6, 2014

A little Coffee for the morning

Opening:

I was challenged by a co-worker to write a website in CoffeeScript (CS) on a Node.js server after telling him my opinion on CS. He said he had the same opinion too but once he started to use CS he really liked it and suggested I give CS a try. So I decided to make a simple webpage using Node.js and CS.

My initial thoughts:

·         Why would anyone want to learn something that only adds an extra step to the development process? You have to compile CS to Javascript (JS) so it will run on the browser.
·         Before you can write CS you have to know JS. As they say “It’s just JavaScript”. Why learn two things?
·         As you write CS you have to make sure you are not breaking anything in CS and/or JS. Yeah if you mess up in CS when debugging life can get very interesting.

What is CS:

Okay what is CS? “It’s just JavaScript”. It is a language that compiles into JS.

Its goal is to make writing JS easier. It does this by taking away some of the oddities that you have to remember when coding proper JS. Here are two examples of this:
·         In JS you have to make sure to use three equal signs instead of two so you compare type as well.
if( 1 === 1) is not the same as if( 1 == “1”)
·         In JS you have to making sure to declare variables with ‘var’ so they are put into the correct scope.
var chicken = “bird” vs chicken = “bird”
It also saves you lines of code since it is like Ruby/Python meaning it is white space delimited and not bracket delimited.
while true
                var chicken = “food”
is the equivalent as the following in JS
                                while( true ){
                                                var chicken = “food”
                                }

The meat:

As I said I was going to make a website using Node.js and CS. Well I did not have any ideas on what kind of website to make so I decided to follow a tutorial I had a while back with Node.js, Express, and Jade. It was from http://goo.gl/lfwbVV. As I re-walked through the tutorial I converted the JS to CS. This process was not as bad as I thought it would be once I figured out the syntax for CS.

I started the converting process with the Node.js server file went from 34 lines of code to 28 lines of code. This is a pretty good save since it is just the base starter server file. The more you type the more you will save. The space saving is because CS is a white space delimited language. It was very nice to not have to remember to use === or var. That alone may be the saving grace of CS and why it has a strong following.

One thing I did find out, you need to convert any client side CS to JS so the browser can run the code. I had two options to do this. One was to use the IDE’s (PyCharm) built in ‘watcher’ functionality or to use CS’s built in ‘watcher’ functionality for this. I went with the IDE’s because I just had to click a button and not type a command (call me lazy). When you add a watcher to a CS file after every save it makes/updates two files. One file is the JS file that the browser/server will run. The other file is a map file this allows browsers like Chrome to be able to allow you to debug the CS code and not the JS code in them. That’s a point for Chrome ^5.

If you don’t want to add watchers to the server side CS file with node you need to add require("coffee-script").register(); to your Node.js server file. The debugger for the IDE I use has a hard time figuring out where the program is when running without the converted CS. So I ended up adding the watchers to the server side CS files anyway.

On the down side in my opinion is that it feels A LOT like Ruby to me and not so much like Python. What can I say Ruby on Rails left a bad taste in my mouth. The other down side is that you have to make sure your watchers are setup so you can debug your code. Those are the only two down sides I can think of if you are doing CS with Node.js. 

In the end of my little learning experience I came to the conclusion CS is great in the Node.js world but a pain in the non Node.js world.

In the end pro and con List:

Pro:
1.       CS allows you to focus on the coding part and not the structuring part of JS.
2.       You are using a white space delimited language. Meaning no braces, brackets, and more. Thus saving you lines and lines of code.
3.       Chrome Dev Tools can debug CS on the client side assuming you set up watchers.
4.       IDE’s can debug CS on the server side. Some require that you add watchers.

Things I don’t care for:
1.       It feels too much like Ruby (not a Ruby fan). Give me Python.
2.       It does add an extra level of complexity for debugging

The END:

I will still use CS for all my Node.js projects moving forward. If you still are on the fence you should give CS a try. Just go ahead and do a simple project with it. Closing thought is MEH it’s nice and all but it was not life changing or life destroying.

Monday, May 26, 2014

TP-Link TL-WN722N USB wireless adapter Beagle Bone Black

So you have a Beagle Bone Black (BBB) and bought the TP-Link TL-WN722N wireless adapter. WOOT me too. Then you went off and installed Debian onto your BBB. Wow you and I are like twins. But now you can't find anything that points you in the directions on how to get your newly found wireless adapter working darn internet. GOOD news this will help you with that.
Note: I'm using Debian distro Wheezy-bbb

Working assumptions you have installed Debian on to your BBB and you do have a TP-Link TL-WN722N. If any of these assumption are wrong then I can't say these steps will work.

Step 1: Make sure your source.list looks like this
cat /etc/apt/sources.list
deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
#deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
#deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
deb http://security.debian.org/ wheezy/updates main contrib non-free
#deb-src http://security.debian.org/ wheezy/updates main contrib non-free
deb http://ftp.debian.org/debian wheezy-backports main contrib non-free
#deb-src http://ftp.debian.org/debian wheezy-backports main contrib non-free
deb [arch=armhf] http://beagle.s3.amazonaws.com/debian wheezy-bbb main
#deb-src [arch=armhf] http://beagle.s3.amazonaws.com/debian wheezy-bbb main

Step 2: If you had to change or add things to the source.list you will need to update your packages
sudo apt-get update

Step 3: Install the wifi libraries.
sudo apt-get install wireless-tools usbutils

Step 4: Download and install the firmware for the wifi card.
sudo apt-get install firmware-atheros
sudo wget http://linuxwireless.org/download/htc_fw/1.3/htc_9271.fw
sudo cp htc_9271.fw /lib/firmware

Step 5: Adding the adaptor info to the interface file.
sudo vi /etc/network/interface
Add to the bottom of the file.
# The wireless interface
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa.conf
Step 6: Plug the Wifi card in.
Step 7: Make sure system sees the wifi card.
sudo iwconfig
root ~ # sudo iwconfig
wlan0     IEEE 802.11bgn  ESSID:"crash_wireless"  
          Mode:Managed  Frequency:2.437 GHz  Access Point: 00:14:BF:05:4A:05   
          Bit Rate=24 Mb/s   Tx-Power=20 dBm   
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          Link Quality=70/70  Signal level=-30 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:264   Missed beacon:0
Step 8: Make the wpa.conf file.
sudo vi /etc/wpa.conf
network={
    ssid="TheSSID"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk="ThePassword"
}
Step 9: Lets start this thing.
sudo ifup wlan0
Step 10: Lets make sure we are connected
root ~ # ifconfig
eth0      Link encap:Ethernet  HWaddr 90:59:af:95:ca:42  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:40 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

usb0      Link encap:Ethernet  HWaddr f6:76:6d:4e:92:12  
          inet addr:192.168.7.2  Bcast:192.168.7.3  Mask:255.255.255.252
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr c0:4a:00:1e:51:c4  
          inet addr:192.168.3.139  Bcast:192.168.3.255  Mask:255.255.255.0
          inet6 addr: fe80::c24a:ff:fe1e:51c4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:183939 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1264 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:27428428 (26.1 MiB)  TX bytes:207095 (202.2 KiB)
Step 11: Do a dance cause it is connected. If not try turning off the BBB and turning it on again.