Sunday, 22 October 2017

Raspberry Pi User Group Meeting (RPUG) - October 15, 2017

Our last meeting at the New Glasgow Library was pretty low key. We are looking at putting together some workshops on basic and some not-so-basic topics.

I really want to make a simple project - a Four Op Amp Function Generator. Forrest Mims provides a schematic in his first Engineer's notebook. You can find all kinds of examples of schematics online. One of the nice things is that it can fit on a single solderless breadboard. There are even IC's that come in packages containing 4 op amps although any op amp should work. I plan on using an LM324. They are on order.

I have some other IC's of op amps, actually some NTE947's for which I used the pinout to redraw the schematic. One of the nice things of drawing schematics using IC's is that you can often just use the old schematic and change the pin numbers specified by the new IC. If you have ever tried to draw a schematic using the pinout of an IC, you will quickly realize that there is an art to the whole thing.

Look for a workshop coming soon.

... by the way, I am also taking a ham radio course with the local amateur radio club, Pictou County Amateur Radio Club.

Here is their link:
Pictou County Amateur Radio Club, http://pcarc.ca/

Saturday, 21 October 2017

ESP8266 / nodeMCU and DHT11

October 21, 2017

This will be a short post. This will have a date on it, I am sure. But, I am posting material that will likely become dated soon, so I want that in the text of the post as well.

The ESP8266 IC is a great boon to the electronics hobbyist. I have been using a nodeMCU version lately and have had some good amount of success although there has been a lot of digging to get things to work correctly.

While using information found on the Web is usually free, I still like books. So, I bought a book: "Internet of Things with ESP8266," by Marco Schwartz - in PDF.

After spending several hours on the small project of getting a DHT11 sensor to work with my nodeMCU, I finally figured out that my DHT libaries were out-of-date. The simple solution was to install Adafruit's DHT library and their Adafruit_Sensor library.

Here is the link to using a DHTXX sensor on Adafruit:
https://learn.adafruit.com/dht/overview

My setup is seen below:




The thing to realize, when you use an ESP8266 module of some sort. is that you need to know what pins are being used in the Arduino code. Here is a typical image of a nodeMCU layout:
A little hint: when you go to write your code in the Arduino IDE, make sure you use the correct pin. Looking at the layout above, D1 is GPIO5. In a typical DHT11 example program you will see digital pin 2 used to get data from the sensor. I changed that to 5, as was in the code in the book. The point is that nodeMCU pins will often not work with with Arduino board code and changes will be needed. Then you also have to make sure you are getting the correct numbers for whatever ESP8266 module you are using.

I will not bother posting the code as you can find it online in different places. Hopefully, it will be enough assistance to those with similar problems in keeping their libraries up-to-date. I guess that is my own lesson as well. If I come across more problems that I are worth posting, I will.

Friday, 6 October 2017

Raspberry Pi User Group Meeting, September 24, 2017

RPUG had its first meeting of the season Sunday, September 24, 2017, 2-5pm.

Where?       New Glasgow Library
                   182 Dalhousie Street
                   New Glasgow, NS

We will be meeting the 3rd Sunday of the month for the rest of the season. Easy to remember but here is the list of the dates:

October 15, 2 - 4:30pm
November 19, 2 - 4:30pm
December 17, 2 - 4:30pm
January 21, 2 - 4:30pm
February 18, 2 - 4:30pm
March 18, 2 - 4:30pm
April 15, 2 - 4:30pm

Once the library closes on Sundays for the season we will be considering whether or not to continue for a couple of months on Saturdays and then stop for the summer.

As I needed the photocells for another project this summer, I took the mounted ones from the robot. During the RPUG meeting we decided to figure out how the line sensor works. Here is a picture of the underside of the robot with the line sensor on the right:
We connected the line sensor to the Boarduino, wrote a quick sketch to test it, and started figuring it out. The nice thing about sensors connected to Arduinos is that many of them have three connections: power usually at 5V, a common or GND, and a signal. The signal tends to be an analog voltage. However, because Arduino often uses the PWM pins to simulate an analogue voltage, I will be checking the output signal of this line sensor with an oscilloscope. If it is truly an analogue output signal, the reading on the oscilloscope will be a steady level voltage. If uses PWM to simulate an analogue voltage, the output will be a rectangle wave with high side, the duty cycle varies with the higher the voltage.

What the ADC sees on the Arduino is that the voltage from the sensor signal actually takes time to fall to zero. If not, the ADC would have to provide numbers that reflected both high and low values of the signal. This topic can be searched on the Web if more is needed.

Here is a simple sketch to test the line sensor:
[code]
/* program: robot_line_follow_2_blog.ino
 * This program is used to test the line sensor only.
 */
int line_sensor = 0;  // variable to hold data from reading infrared sensor on A3

int analogPin3 = 3; // the line sensor is connected to this ADC

void setup() {
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int drive_type;
  Serial.println("Inside loop");
  line_sensor = analogRead(analogPin3);
  Serial.print("line_sensor = ");
  Serial.println(line_sensor);

  delay(1000);
}
[/code]

When the sensor is first tested, it could be that it is not adjusted properly. We figured that out without too much experimenting and without looking up a tutorial online. In the picture there is a trim pot with a white top that allows for a Phillips head screwdriver. With the sensor powered, turn the pot until the red LED turns on.

At that point, when the program runs, the red LED should shine and placing something black under the sensor will turn the red LED off and the readings will change from a low number (around 8 to 12 with no dark object) to a high number (around 800 to 920 with a dark object). When this happens, you know the line sensor works properly.

It might happen that your line sensor goes from on to off when you set the robot (or whatever your project is) down. Readjust the trim pot and set it down again. Keep adjusting the trim pot until the red LED stays lit. Test again.

What happened to us when we first tested it were ADC readings that varied from  800 (no black object under the sensor) to approximately 920 (with a black object under the sensor). You could operate your line sensor that way and write your program accordingly. This might even be useful if your line to follow might be some other colour than dark black. The red LED was not lit when the line sensor was used in this manner.

We also took some time to test the motors by using some arbitrary programming. The idea was to get the robot to turn one direction and then the other. It only turned left and periodically more sharply left than others, even when it was told to go right. Looking back it is, what was happening was the use of PWM on geared motors needs the motors to be signalled to completely stop or changed direction for a long enough period of time so the momentum does not carry the robot through its last turn.

Look for some general electronics tutorials in the future, especially to be provided at the RPUG Meetings. I am currently working on one involving 555 and 556 timers - Forrest Mims' Stepped Tone Generator (on the Web aka APC or Atari Punk Console). Another planned tutorial for the near future is a commonly found Four Op Amp Function Generator. However, my addition will be control of frequency using an Arduino to provide high resolution control with an R-2R Ladder Network DAC. It would be in the neighbourhood of 16-bit resolution with two 74HC595 shift registers. Of course, some of these will also look on putting an RPi spin on the topic.

Sunday, 18 June 2017

Raspberry Pi User Group, June 17, 2017

Happy Father's Day to all the fathers out there, and their families!

Today is also the day of the Johnny Miles marathon and we still have runners going by the house. Lots of the energy there!


Raspberry Pi User Group Meeting, June 17, 2017
Place: New Glasgow Library, New Glasgow, NS


Arduino / Python Serial Communications Using PySerial:

We had a Raspberry Pi User Group Meeting yesterday, June 17th. I was working on my robot yesterday. I am working through some tutorials on YouTube about Arduino and Python Serial Communications. I had looked up a number of tutorials online and worked through a couple of them. However, whenever I tried to do something that expanded on the ideas presented, it never worked. That is why I did some more searching and found the topic above.

Here is a link to the first video of a good set:
https://youtu.be/KB67cuaEJOU?list=PL5YMW87TmMmUBdNSM7dDS3-1WLwEUkhFU

These videos are short and very relevant to how I want to use an Arduino and a Raspberry Pi Zero Wireless together on my robot. To make things really simple, I am using a USB cable to interface Arduino and Python. For testing and learning purposes, I am using a PC running Ubuntu with my Arduino. Using Linux and Arduino really cuts down on prototyping time as the programs compile and upload very quickly with such a system. It also works fairly quickly to actually develop on the Raspberry Pi Zero W but, there it time to go back and forth between the RPi and a PC to view any kind of web-based tutorials.

By the way, this topic uses PySerial and works with Python 2 and Python 3.


The Robot:

This is my robot in its current state:

This is a mess of wires! However, if you take the time to look through the wires,
you can see the USB Boarduino in the middle, the photocells are to the left setup as voltage dividers with the resistors in the breadboards. The new additions as of late are the H-bridge motor drivers on what is the front right and right side of the robot. I placed the RPi Zero W and a USB hub to give an idea of what is to be added. It looks like I will have to add another layer to the chassis to fit the other devices. I might also add a 16x2 LCD and some push buttons. Once I get it going, I will consider refactoring it by soldering together some permanent circuit boards for the H-bridge motor drivers and the photocell/resistor voltage dividers to free up the solderless breadboards.


Underneath are the geared motors with wheels, the battery pack with
rechargeable batteries, and the swivel caster wheel. The battery pack is held in place with two elastics. You can also see the IR sensor on the bottom that will allow the robot to be line-following. It is not hooked up yet as I have not made it light-following yet.
 The motors work and so do the photocells. I need to normalize the three photocell/resistor voltage dividers to allow for easy programming of signals going to the motor drivers. That way it will follow light uniformly for light shone on all three photocells.


PAW Server:

For a change in direction, and possible use on a robot at some point, we checked out running a web server on an old Android phone. I chose a tutorial on the PAW Web Server which is a simple app that runs on Android without having to root the device. It has some excellent features but keep in mind that a single-core 800 MHz, 512 MB RAM device will not run much at blazing fast speeds.

All the same, it is fun to use a webcam server, robot text-to-speech, and of course, serving up actual webpages. There is too much to describe but it looks very useful and the interface is very easy to use. Just search for tutorials on the PAW Server and you should find something to guide through orientation.


List of Topics To Date:

Here is an updated list of things we have worked on or covered in some way, to date:
  • Raspberry Pi radio - your own little FM broadcaster!
  • Command line music players and how to use them to edit music files
  • FlightRadar24 - watch airline data
  • How to set up your RPi the first time
  • Minecraft Pi workshop - programming in Python to make your own custom Minecraft game
  • How to make an LED turn on and off using Python and RPi General Purpose Input/Output (GPIO) pins
  • Free RPi material such as magazines and short books provided by "The MagPi" magazine
  •  Setting up your own private LAN (not Internet accessible). This is useful for places where organizations keep their own Internet Accessible LAN locked down. This means you cannot do simple things such as using SSH to login into your RPi. If you set up your own private LAN, you can connect both your PC and RPi and login remotely using SSH.
  • Run a servo motor using Python.
  • RPi 3 as desktop PC replacement - would do if that was all you had but, not really recommended.
  • RPi 3 - 3.5 inch touchsreen
  • Starting to explore Arduino/RPi Zero W USB communications (same as Arduino/Python Serial Commuinications)
  • Forward/Reverse Relay modules
If you would like to see something specific covered, drop me a line! You can also drop by the meetings once they resume again in September, 2017.

Wednesday, 7 June 2017

Raspberry Pi Zero W and Arduino Robot, June 7, 2017

Here is a quick post to show the current state of my robot. It is currently to the point where I have all the necessary components except maybe the transistors necessary to make H-bridge motor drivers for each wheel. I have transistors that might work but have not built an H-bridge to test them. I am using geared motors, a USB Boarduino, an RPi Zero W, some mini solderless breadboards, a powered USB hub, three UBEC's that supply 5V, 3A, some photocells, an 8-cell AA battery pack with rechargeables and a homemade chassis from plywood.

The photo shows everything running from AC/DC adaptors at moment. However, everything has been tested with homemade USB power cables. I just hope I do not make the mistake of plugging in the positive and negative of those USB cables into the same connection. I saw a recent product that offered the same power from a USB port that ran the power connections out to red and black shrouded alligator clips. The tweet said an accident waiting to happen!

Current state:

At the moment, with the programs I am running, I can send a number from the RPi Zero W by USB to the Arduino and have the Arduino light up and LED that number of times. The next stage is to use directional controls commonly used in video games, W, A, D, and S, to light up the LED's. I would also like to be able to adjust the brightness according to how long I hold down the directional key using PWM on the Arduino.

That way I know the current setup is ready to accept a more fully developed program that will accept both directional controls using Python on the RPi Zero W as well as using the photocell light sensors. Keep in mind, PySerial is used.
After finding a number of different tutorials on using PySerial with an Arduino, here is the one I found the most useful (easiest to use and mod to my purposes):
http://www.instructables.com/id/Interface-Python-and-Arduino-with-pySerial/

My apologies if the code does not copy correctly. I copied and pasted the code into Blogger then edited it where needed. Here are the two programs I am using to control the LED's at this time:


Python code:
# program: control_arduino_leds.py
# This program sends data from the RPi over USB to an Arduino and receives
# that data back - repeated. The data sent to the Arduino controls the number
# of times the LED's light up on the Arduino.
# The pair program for the Arduino is receive_from_pi_light_leds.ino
from time import sleep
import serial
ser = serial.Serial('/dev/ttyUSB0', 9600) # Establish the connection on a
# specific port

counter = 7
# testing number, 48 is the character 0, zero, 57 is 9
# Below 32 everything in ASCII is gibberish
try:
  while True:
    ser.write(str(chr(counter))) # convert the decimal number to ASCII then 
                                 # send it to the Arduino
    print "counter = %d" % counter
    print ser.readline() # read the newest output from the Arduino
    sleep(0.5) # delay from 1/10 seconds
    if counter == 255:
    counter = 32

finally:
  ser.close() 

Arduino Sketch:
// program: receive_from_pi_light_leds.ino
/* This program receives data from the RPi over USB and sends data back. Before
 * sends the data back, it calls a function to light one or more LED's according
 * to the data received. 
 * PAIR PROGRAM on RPi: 
 */
int led1 = 13; // led is connected to digital pin 13 
int led2 = 12;

void setup() { 
  pinMode(led1, OUTPUT); 
  pinMode(led2, OUTPUT);
  Serial.begin(9600); // set the baud rate
  Serial.println("Ready"); // print "Ready" once
}

void loop() {
  char inByte = ' '; if(Serial.available()) { // only send data back if data has been sent
  char inByte = Serial.read();  // read the incoming data
  light_leds(inByte);
  Serial.println(inByte);  // send the data back in a new line so that it is $
                             // all one long line
  }
  else if(!Serial.available()){
    stop_go();
  }
  delay(100);
}

void light_leds(int n) {
  for(int i = 0; i < n; i++) {
    digitalWrite(led2, HIGH);
    Serial.println("inside light_leds");
    Serial.println(char(i+48));
    delay(500);
    digitalWrite(led2, LOW);
    delay(500);
  }
  Serial.println("light_leds END");
  delay(3000);
  Serial.println("going to stop_go");
  stop_go();
}

void stop_go() {  // does nothing at this point
}

Sunday, 4 June 2017

Raspberry Pi User Group Meeting, May 27, 2017

Next Meeting:    June 17, 2017, 10am - 2pm @ New Glasgow Library
Check out Kijiji.ca New Glasgow, NS for current ads.

Unfortunately our date had to be changed from our regular Sunday to a Saturday due to the library closing on Sundays halfway through May to the beginning of September. We did have the new date posted on our Kijiji ad but the message did not get out to some people - sorry about that.

There was some time at the beginning of the meeting where I was by myself. I took the time to work on my robot. Connecting the photocells was the first job. I had one photocell connected more or less the way I wanted by the time the first attendee arrived.

Here is the robot with just the photocell (light) sensors and one solderless breadboard, and wheels with geared motors. The screws for the third wheel (a caster wheel) can be seen in three places. To start with, I originally used a screw that was too long for the job. Grounding it down so it would not interfere with anything that might be placed on that section of the robot was too much trouble. Although I left the one ground down screw in place, I went and bought the correct length screws for the rest of the caster wheel mounting holes.








Here are is the robot with LED's connected so that they light up according to which sensor has the most light shone upon it. The LED's are on the far side of the board behind the light sensors.



Our attendee had some modules he wants to use to construct his model train environment. We started off with a forward-reverse relay module purchased from eBay. These modules were from China but had some decent documentation in English. Once we started to work with them, we figured it out. We also found the eBay listing for the same module and watched the video which was close-captioned in English. Watching it in action on the video helped.

One interesting thing we found was that the model train power supply was not not appropriate to run the relay modules. One of them just would not power up. Luckily, we had an Arduino board from which we used the power supply. So, if you are into model trains or interested in getting started with model trains, make sure you have at least one good power supply to test your equipment.

Here is the link to the module:
http://www.ebay.ca/itm/2x-DC-5V-6V-8V-9V-12V-Motor-Forward-Reverse-Time-controller-Delay-Relay-Module-/331638809913?hash=item4d3736a539:g:kCkAAOSwLpdW~JR3


In the case of testing the relay module, we did not provide a load to switch on so we only had to worry about the current and voltage necessary to run the module electronics used to determine the timing for the forward-reverse cycles. We did not have to worry about the power supply for a motor or how to hook one up. We could hear the relay switch when it powered to indicate it was working.


When borrowing the power supply built into any board, you should have a quick look to see what the power supply circuit can handle. You can do this for Arduino by going to the Arduino website and looking for the relevant board. Look for the hardware schematic. For an Arduino from 2009, the voltage regulator is an MC33269. One of the key properteis to look at when reading the data sheet is the maximum current supplied by the particular device. In the case of the Arduino board, you should also check for Arduino documentation to see if there is anything specific done to the voltage regulator that allows for less or more current than normally supplied by the voltage regulator. Do a web search on the part or go directly to the manufacturer's website to find their data sheet. There are also some sites that provide data sheets from most manufacturers.

We had another module to search for: a servo motor shield. This was easy as it gave the manufacturer on the Arduino shield, what is was, I cannot recall. Do a websearch on "Arduino motor shield" and you will come up with a number of results that will likely serve your purpose. If the websearch provides you with an acceptable result, you should be able to find a relevant tutorial.

Come see us at the library Saturday, June 17, 2017 to see what new things we are using and troubleshooting. The robot should be able to follow light by then! If you look closely, you can see that there is actually no RPi on the robot yet! Give it time.

Saturday, 13 May 2017

Raspberry Pi User Group Meeting, April 30, 2017


We had somebody new come in to see what we had to offer Sunday afternoon on April 30th. Our guest had a 3.5 inch touchscreen purchased from eBay that he wanted running. We had not done this before ourselves but were quite comfortable looking up different sites for specific resources and tutorials. We quickly found something that almost had all the functionality working. We could not get all the capabilities working for the touchscreen but it worked with a keyboard and mouse. Given a little more time and knowledge we could have figured out the specific problem with this particular distribution of Raspbian.

The rest of the afternoon was spent working through a couple of tutorials of programming an Arduino with a Raspberry Pi Zero Wireless and serial communications via USB cable. What a great little system it is that allows such a small computer to program and operate an Arduino. The RPi Zero Wireless has a processor about equivalent to the original RPi Model B and 512MB of RAM in a size less than half an RPi 3, Model B. The intended use of this type of setup is to run a motorized robot with a good amount of computing power with the stable motor driving and miscellaneous electronics peripheral capabilities. For instance, servo motors are more stable using an Arduino compared to an RPi. Keep coming back and you will see something develop.

If you have not checked us out on Kijiji.ca, we meet about once per month on a Sunday at the New Glasgow Library. We are usually listed in their events which can be found here:

http://www.parl.ns.ca/events/index.php

Our next meeting is May 28th, 2 - 5 pm.

If you are interested in us, make sure you look up the correct library. We meet in the Community Room at the New Glasgow Library. There is also a Raspberry Pi, Model B, available for anybody to come in a use on request. I recommend a little reading about it before you use it. This goes for all people who have not really used a DIY electronic device with any number of electronics pins (aka in electronics as GPIO) used to connect things like LED's and pushbuttons.

V = IR is a good equation to know how to work.

Basically, if you connect an LED to a pin, make sure to use a resistor of at least 100 ohms. If you neglect to use a resistor or use a resistor of too low a resistance, you will permanently lose use of that pin or sometimes worse. Do a websearch on the subject and you should find lots of tutorials. Check out the blog post here for a specific application:

http://tinturesoftech.blogspot.ca/2017/01/


The great news is that you can still use the Raspberry Pi with very little electronics knowledge just as a computer. It does all the major things that a computer will do such as listing files and directories, making files, editing files, changing file permissions, working with shell scripts and the like.

A great resource is The Magpi, the Raspberry Pi magazine which can be found on the Raspberry Pi website. You will find lots of reading material and projects in this magazine. It also has a great and growing collection of small PDF's on essential subjects that help in the process of getting to know the Raspberry Pi, including one on the DIY electronics.

The link below will get you to the RPi site. Have a look around - it is worth it to find out about the RPi.

https://www.raspberrypi.org


If you are uncomfortable with plugging things into the Raspberry Pi but still feel the desire to make something turn on and off, try looking up a video on the subject. It will help immensely. You can find a large number of videos on how to connect things safely, though not necessarily having safety in the title. A little knowledge goes a long way. At the same time, use common sense. An LED is a great device to learn how to use. First try using an LED, a 9V battery (no higher), a current limiting resistor, and necessary jumper wires.