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.

No comments:

Post a Comment