Tuesday, November 24, 2015

Voice Display Board Completed

1.0 Recap


In a couple of earlier posts we described the design and construction of a voice display and driver board which would emulate that used by Kitt in the Knight Rider TV show. This has now been completed and mounted on AVA.



When we connected the voice display unit to the EMIC 2 Speech Synthesizer which AVA uses to talk, we discovered a problem. The display was driven hard on, even when AVA was silent. A quick measure with the multimeter showed that the EMIC 2 has a constant 2.4 VDC offset. As discussed in the earlier post, the LM3915 displays full scale at 1.25 V, so that was why all the LED's were on.

This is not unusual and a lot of the Arduino MP3 shields do the same thing. Unfortunately when we were testing the prototype, the EMIC 2 hadn't arrived from the USA so I tested using the piezo analog output on the Arduino (which doesn't have a DC offset).

2.0 High Pass Filter


There are a number of ways that you can remove the DC component of a signal, so that you are just left with the AC component. You could use an isolation transformer, but we didn't have one in the spare parts bucket. We did have a heap of resistors and capacitors so we decided to try a high pass filter.

A high pass filter, as the name suggests, passes signals above a selected cut-off point, ƒc eliminating any low frequency signals from the waveform. The circuit for a first order high pass filter looks like the following.

It delivers a response curve (courtesy of http://www.electronics-tutorials.ws/filter/filter_3.html):


It is generally accepted that the range of frequencies audible to humans is 20Hz to 20kHz. Consequently we will design our HP filter with an fc of 20Hz. The formula to calculate fc for a first order high pass filter is:


You can pick two variables and solve for the third, or you can go to an online filter design calculator, and let it do the hard work for you.

We selected an fc of 20Hz and a capacitor of 0.01uF (because we had one of this value), and the design site spat out a resistor value of 820k. If you plug in these values into the formula above you will get an fc of 19.4 Hz which is fine. The filter design site will even plot frequency and transient analysis graphs for you.



3.0 Conclusion


Adding the high pass filter between the EMIC 2 Speech Synthesizer and the voice display module did the trick. It removed the DC bias and allowed the speech signal to pass through. Here is a video of AVA speaking with the voice display module installed.


Saturday, October 31, 2015

Sharp GP2Y0A02YK0F IR Distance Sensor (20-150 cm) Arduino Library

Distance Measuring Options


If you are building an autonomous robot then you need to have some sort of obstacle avoiding sensors. I have attached a Parallax PING ultrasonic sensor to the front of AVA using a servo (so that I can scan 180 degrees). Ultrasonic sensors are generally pretty accurate but since they use reflected sound to calculate distance, they don't perform well if the obstacle is sound absorbing. Ultrasonic sensors can also miss thin objects or objects that reflect the sound away from the sensor. However, the range of ultrasonic sensors is much better than IR. For the PING, the available sensing range is 2 cm to 3 m.

To address the ultrasonic issues, I also mounted a Sharp IR Distance Sensor (GP2Y0A02YK0F) above the PING. The IR sensors don't perform well outside but indoors there accuracy is good enough as long as you stay within the quoted detection limits. IR sensors are generally cheaper than ultrasonic, their beams are more directional (narrower) and reflectivity of the surface is more important than the sound absorbing properties of potential obstacles.

Putting the two sensors together is complementary and allows the short comings of both sensors to be addressed (to an extent).

Sharp GP2Y0A02YK0F IR Distance Sensor (20-150 cm) 



Sharp manufactures a range of IR Distance Sensors. For the front sensor I selected the GP2Y0A02YK0F, which has a usable detection range of 20 to 150 cm's.

The Sharp GP2Y0A02YK0F measures distances in the 20–150 cm range using a reflected beam of infrared light.  By using triangulation to calculate the distance measured, this sensor can provide consistent readings that are less influenced by surface reflectivity, operating time, or environmental temperature.  The Sharp GP2Y0A02YK0F outputs an analog voltage corresponding to the distance to the reflecting object.

If you have a look at the GP2Y0A02YK0F datasheet, you will see that the analog voltage output does not have a linear relationship to distance. You can also see that the values go crazy below about 20 cm.


Noah over at the Arduino Mega Blog has reversed engineered this plot to work out the relationship between distance and the output voltage.

distance = 10650.08 * sensorValue ^ (-0.935) - 10 cm

Sharp GP2Y0A02YK0F IR Distance Sensor Arduino Library


To connect to an Arduino and get a distance you could just use Noah's formula above, but sometimes it is easier to wrap the complexity up in a library. I did a search and didn't find an existing library, so I decided to do one myself. Partly because I haven't done one before.

I did find a library for the GP2Y0A21YK IR Distance sensor (10 - 80 cm), but the characteristics must be different to the GP2Y0A02YK0F as the distances provided by the library are way off. Noah's formula on the other hand, provides very good correlation with the distances measured by the PING. For consistency, I based my library on what jeroendoggen did for his.

You can download the Sharp GP2Y0A02YK0F IR Distance Sensor (20-150 cm) Arduino Library files, and then follow these instructions to use it:

Instructions:

  • Create a directory called GP2Y0A02YK0F within the libraries sub directory where your Arduino sketches are saved.
  • Copy GP2Y0A02YK0F.h, GP2Y0A02YK0F.cpp and keywords.txt into the GP2Y0A02YK0F directory.
  • Within the GP2Y0A02YK0F directory, create a sub directory called examples.
  • Copy DisplayCM.ino into the examples sub directory.
  • Restart the Arduino IDE to see the new library.

Sharp GP2Y0A02YK0F Mounted on AVA


The following photo shows the Sharp IR sensor mounted above the front PING on AVA. I have fitted a sensor shield to the Arduino Mega which makes it very easy to connect the various sensors to the micro controller.



Friday, October 23, 2015

Connecting the Duinotech 3 Axis Compass to an Arduino

1. Duinotech 3 Axis Compass Magnetometer Module

*******************************
EDIT - 14 October 2022

You will see in the comments below that some time in 2021, something changed with the Duinotech 3-axis magnetometer and the Honeywell HMC5883L Arduino libraries stopped working.

I recently purchased a new module and compared it to the original I bought in 2015. They are very different, in particular there is one less pin and the magnetometer IC and supporting components have changed.

I've done a full write up on the Reefwing Medium site. If you can't be bothered reading this, the new chip being used is the Memsic MMC5883MA. I list some compatible Arduino libraries in my article - so you should read it!

*******************************

At a recent mini maker faire, I purchased the duinotech 3 Axis Compass Magnetometer Module (Part Number: XC-4496) from the Jaycar Electronics stand. I thought this would be handy for calculating heading information for AVA the robot.

Unfortunately, the module comes with no instructions and just these very brief specifications:
  • Operating Voltage: 5VDC (or 3.3 VDC)
  • Resolution: 12 bits
  • Interface: I2C
  • Includes: 5V to 3.3V level shifter (so you can operate it from 5 VDC)
  • Dimensions: 20(L) x 16(W) x 5(H) mm
We know that the module communicates via I2C but without knowing the module address or the available instructions, this isn't much use. No problem, I'll head over to the Jaycar website and look up the technical specs. Bzzzzzzzt! If you click on the link above, you will see the only information provided is the specifications printed on the packaging. It appears that Jaycar are moving away from Freetronics for their Arduino compatible boards, shields and sensors to duinotech a Chinese manufacturer. I assume they are doing this based on cost, the Freetronics stuff is good quality and very well documented. 

2. Honeywell HMC5883L 3-Axis Digital Compass IC


If you have good eye sight you will see HMC5883L printed on the PCB. A quick google will determine that this is a 3-Axis Digital Compass IC produced by Honeywell. The HMC5883L Data Sheet is very comprehensive and requires everything that you need to interface the chip to an Arduino via I2C. The duinotech module is apparently a break out board for the HMC5883L, similar to the one produced by SparkFun. It is in fact an improvement on the SparkFun version in that it can be driven from 5VDC and the interrupt line is also broken out.

3. HMC5883L Arduino Library


Armed with the data sheet you could work out how to get the module talking to an Arduino but as usual, a number of people have already done the hard work for you. I ended up using a library written by Korneliusz Jarzebski, a Polish chap. The HMC5883L Arduino Library is accompanied by a tutorial, which is in Polish but google translate does a pretty good job of converting this to English.

One thing that the library is missing is the keyword definition file which the Arduino IDE uses to colour highlight defined library names and methods. I have produced a keywords.txt file for the Jarzebski HMC5883L Library which you are free to download and use. It includes all of the public methods exposed by the HMC5883L class.

To use the library, create a folder called HMC5883L in the Arduino libraries folder. Within this copy the HMC5883L.h and HMC5883L.cpp files from the Jarzebski Github repository and the keywords.txt file. Also create a sub folder called examples and copy the HMC5883L_calibrate,  HMC5883L_compass, and HMC5883L_simple files into it. You will need to restart the Arduino IDE to see the new library. The HMC5883L_simple sketch example shows how to use the library and test your module.

Here is a quick video which shows the HMC5883L mounted on my robot AVA. On the OLED screen you can see when the compass is connected and the observed heading when the text scrolls up.


Tuesday, August 11, 2015

Importing Robot Parts from the USA - How not to do it!

1. How Not to Do It


As mentioned previously, we are using the Arlo robotics platform as the base for AVA. We placed an order with Parallax for the bottom and top decks, power distribution board, motors, wheels and a bunch of sensors on the 14th July. The total cost was USD939.67 and shipping cost USD 119.10. So far so good.

What I didn't know (or more likely had forgotten) was that importing anything worth over AUD1,000 attracts the attention of Australian Customs. To summarise the current situation:
  • For goods that are worth equal to or under AUD1,000, there are no duties, taxes or charges to pay.
  • For goods that are worth more than AUD1,000, you will need to fill out a special form called an Import Declaration, and pay duties, taxes and charges.
  • You will need to pay duties and taxes on some goods (like tobacco or alcohol) regardless of their value
  • Certain types of goods are not allowed to be brought into Australia, or else need special permits.
So stupidly, we placed an order for just over $1K Aussie. This is where you disappear down the rabbit hole.

2. Then Things get Difficult


On the 31st July, I got notice from Parallax that they had shipped the order. Woo Hoo! Parallax provide a helpful link which allows you to track the package as it wings it way to you. On August 4th, the package landed in Australia and then I started seeing the dreaded "Held in Customs" message. No problem we thought, there must be some sort of clearance process, a day or so and the package will be on its way. Nope. On the 10th August we receive a formal letter from Australia Post stating that "the goods you are importing are being held, pending completion of Customs formalities". What's more if you don't sort this out promptly you will start being charged a daily storage charge (called Demurrage - because storage charge would be too obvious) and after a month, the goods will be returned to the sender.

3. Exiting the Rabbit Hole


Mental note - don't order goods worth over $1k on the internet again! Ok, how do we sort this mess out? Australia Post helpfully provides another 2 pages of instructions of where to from here. The process is as follows:
  1. Download and complete import Declaration (N10) - Post (Form number 8374) Including Tariff Classification.
  2. Submit an Import Declaration  to Department of Immigration and Border Protection (DIBP).
  3. Your import declaration is assessed for Duty and GST. Allow 5 working days for this, unless additional documentation is required (of course it will be). There is also a manual processing charge of $48.85 on top of the Duty and GST.
  4. You then receive a payment advice. After payment processing which takes up to 3 days, Australia Post is notified that they can dispatch your goods. Expect delivery in 1 - 7 days.
When I stopped crying and the alcohol therapy had done its job, I pulled myself together and said "we can do this!"

4. I was wrong...


I did manage to download "Import Declaration (N10) - Post (Form B374)". This electronic form has a helpful feature that prevents copying and pasting so you need to type it all in. No problems, the bureaucracy and their 13 digit identification codes won't beat me! Then you get to the tariff classification and statistical code section. The first bead of sweat appears. Perhaps Dr Google can assist. Apparently there are 13,000 customs tariffs and 4,000 concessions. You read on, you have to provide the tariff classification and statistical code for every line item in your order. We have 16 items in the order and are starting to feel sick. Then there is Section 243T, which means that Customs can hit you with a Strict Liability Penalty of $2,550 should you get the declaration wrong (even unintentionally).

5. Plan B


We quickly came to the conclusion that we were out of our league. Difficult as it is to believe you are better of hiring a licensed customs broker to manage this process for you. We used eCustoms Broker (for no other reason than they came up first on the search list) but have been very happy with the results. They process the form in one day (3 hours if you are really impatient and want to pay a bit more) and charge $77. There is an electronic processing fee of $40.20, which is cheaper than the manual fee if you do it yourself. I had to pay the GST of $144.39 but because Australia has a Free Trade Agreement (FTA) with the US you don't have to pay duty if the goods are manufactured in the US. I'm not sure how difficult this concession would have been to get if you did it yourself but it would add at least add another 5 days as there is another form to fill in. For the speed and not having to wade through 13,000 tariff codes I'm happy to pay $77. The only difficult part was explaining what the parts were for and what the robot would do...

6. Changes from 2017


At a recent meeting of State and Federal Treasurers it was agreed that from 2017, there will no longer be a $1000 threshold for the GST for online purchases.

That means, in 2017, everything you buy online, no matter the cost, will be at least ten per cent more expensive. This will come into effect from July 1st of that year - so buy up now!

Wednesday, July 29, 2015

Voice Driver Board - Kitt Display

1. Overview


In our last post we described the display board which consisted of the six DIL LED bar graph displays and their associated current limiting resistors. The input to the LED Driver Board is a 10 pin header and +12V (which will come from AVA's power distribution board powered by two 12V SLA batteries in parallel). The purpose of the driver board is to take in an audio input signal, feed it to a LM3915 Dot/Bar Display driver chip, which then sinks the current from the display board LEDs via transistors, when they need to turn on. It does this using the 10 pin header which connects the two boards.

2. Header Connections


The 10 pin header is labelled A to J. On the display board, pins A, B and C connect to the first 3 LEDs on the middle bar graphs. Note that the lower bar graph connections are the mirror image to the top bar graphs. Pin D connects to the first LED of the outer bar graphs and LED 4 of the inner ones. Pin E then connects to the 2nd LED of the outer bar graphs and LED 5 of the inner ones. This pattern continues for the rest of the pins. The last 3 LED's on each of the outer bar graphs remain unconnected. By connecting the LED's in this fashion we get a display which simulates a mouth moving based on the audio level of the sound.



On the driver board, pin A of the header is driven by the LED 1 input on the LM3915. B is controlled by LED 2 and so on. The LM3915 senses analogue voltage levels and drives the ten LED inputs to produce a logarithmic 3 dB/step display. Consequently (from the data sheet), the LEDs will turn on at the following approximate audio power levels:

A - 0.2W
B - 0.4W
C - 0.8W
D - 1.6W
E - 3W
F - 6W
G - 13W
H - 25W
I - 50W
J - 100W

3. LM3915 Display Driver Setup


Using the LM3915 is fairly straight forward. Pin 1 and pins 10 to 18 are the LED driver inputs (see schematic above). Pin 2 goes to ground. Pin 3 (V+) goes to the 12V supply (max 25V). Pin 4 goes to ground if that is your bottom voltage range (which it is for us).

Pin 5 is the signal input. We want a maximum of 1.2V, so we use a voltage divider to step this input down. The input at pin 5 can withstand voltages of +/- 35V and an input current of +/- 3mA without damage. The audio output from the Arduino will be at most 5V (but less than this in practise as we are using PWM to drive the piezo). The formula for a voltage divider is:

Vout = Vin (R2 / (R1 + R2)
         = 5V x (10k / (18k + 10k)
         = 1.8V

Note that full scale has been set to 1.25V (see below), so we are overdriving this a tad theoretically but in practise that turns out not to be the case. We are nowhere near levels which would damage the chip.

Pin 9 selects the mode of the display driver. Leave it floating for dot mode, connect it to the supply voltage (pin 3) for bar mode. We added a switch so that you can select the mode.

Pin 6 is the full scale voltage level. We have connected this to pin 7 which is the LM3915 internal voltage reference which delivers a nominal 1.25V between pin 7 (REF OUT) and pin 8 (REF ADJ). To calculate the current which will be sunk at each LED input pin, we refer to the data sheet formulas:

Vref = 1.25V (1 + R2/R1) + R2 x 80uA
        = 1.25V (1 + 0) + 0
        = 1.25V

ILED    = 12.5V/R1 + Vref/2.2k
          = 12.5/1000 + 1.25/2200
          = 13 mA

This would be fine if we were connecting an LED directly to the LM3915, but we can't do that because we need to drive up to 6 LEDs per input (have a look at pin D on the display board). We want the current through our LEDs to be 10 to 15 mA, so we need to be able to sink up to 90 mA. Note that from the data sheet, the max LED current is 13 mA (from the electrical characteristics table). This explains why we need the transistors.

Capacitor C1 (2.2uF tantalum) is required if leads to the LED supply are 15 cm (6 inches) or longer.

4. Transistor Switches


In order to sink sufficient current for up to 6 LEDs we will use transistors to switch them on and off. We have selected the BC 557 which is a general purpose PNP transistor. This transistor can handle a max current (Ic) of 100 mA and a max voltage (Vce) of 65V. It has a DC current gain between 125 and 800.

We use a PNP transistor rather than the more common NPN variety because we need the current to flow out of the base and into the LM3915 LED input to turn the transistor on. In a NPN transistor the current flows into the base.

PNP Transistors can be thought of as being normally OFF but a small output current and negative voltage at its Base ( B ) relative to its Emitter ( E ) will turn it ON allowing a much large Emitter-Collector current to flow. PNP transistors conduct when Ve is much greater than Vc.

To cause the Base current to flow in a PNP transistor the Base needs to be more negative than the Emitter (current must leave the base) by approximately 0.7 volts for a silicon device.

The voltage drop across the current limiting resistor on the display board is the supply voltage (12V) minus the LED forward drop (2V from the data sheet), which gives us 10V. Thus,

ILED = 10V/180 = 55.5mA

However, this current is distributed among 7 LED's, and so typically will be more like 8 mA per LED.

The LM3915 LED inputs are at V+ (i.e. 12V) when off and close to ground when on.

We know that:

Ie = Ib + Ic; and

DC Current Gain (Hfe or Beta) = Ic/Ib (= 125 to 800 for a BC 557)

Consequently, when the LM3915 input is ON, the corresponding transistor is also turned hard on (saturated) and the LEDs associated with that pin are also turned on. The voltage at the base when turned on is 10V - 0.6V = 9.4V. Based on this voltage across the 1k base resistor we can calculate the base current:

Ib = 9.4V/1000 = 9.4 mA

Based on a typical gain of over 300 this may suggest an Ic above the maximum 100mA but this wont happen because the transistor is saturated and at most will draw the ILED of 55.5 mA calculated above. It is not a bad idea to overdrive the base current (within the limitations of the transistor) as this makes the design conservative and beta drops off with high speed switching (MHz so not really a consideration for audio frequencies).

When turned the LM3915 inputs are OFF, the transistor is also OFF, there is no base current and hence no collector current and the LEDs are OFF.

5. Main Driver PCB


The image below shows the final main driver printed circuit board. When connecting to the display board, note that the order of the header (A-J) is reversed.



Wednesday, July 22, 2015

Voice Display Board - Based on Kitt from Knight Rider

1. Overview


While waiting for the mobility platform parts to arrive from the US, I decided to start a side project. I liked the idea of having some sort of visual indication for when AVA was communicating and coincidently came across a voice display board advertised by Think Geek (which says it all really). This display is a simulation of that used by Kitt the robot car in the TV show Knight Rider.


Following a quick internet search it became apparent that there were two main approaches to developing a display like this, analogue or digital. Given that the rest of AVA was largely digital I thought I would go old school and try the analogue path.

The Kitt display is basically a VU (Audio Power) meter reflected horizontally. To make things simple, Texas Instruments produce a chip called the LM3915 Dot/Bar Display Driver which does most of the hard work and is designed for exactly this application. The LM3915 senses analogue voltage levels and drives ten LEDs to produce a logarithmic 3 dB/step display. The LM3915 even provides a regulated LED current supply, eliminating the need for current limiting resistors.


The logarithmic output is suited to signal inputs with wide dynamic range (like audio levels, power, light intensity and vibration). There is also a linear version of the chip which could be used for things like battery level and I may incorporate one of these in a later project.

2. Prototype Design


To ensure that this design works as advertised and to identify any design issues, I built a quick prototype and hooked it up to AVA's logging Arduino (which is the only thing which makes a noise currently). Eventually the robot will have a voice synthesizer, but one step at a time.

Based on the audio power meter design from the LM3915 Data Sheet, I built a version on a breadboard. Note that the LED bar graph doesn't have it's polarity marked (that I could see), a quick check with a multimeter indicated that the anode is the side with the writing.


This works ok, but highlighted a few issues:
  1. The PWM digital output on the Arduino which drives the piezo to make the robot sounding beeps, has sufficient residual voltage when making no noise to light a couple of the LEDs.
  2. The voltage output from the Arduino is low enough that it doesn't need the voltage divider formed by R1 (18k) and R2 (10k). Consequently the audio signal can plug straight into pin 5 of the LM3915. This pin can handle +/- 35V without damage so we are pretty save with our 5V Arduino.
  3. The LM3915 can only sink a maximum of 13mA of LED current (see data sheet electrical characteristics table). To produce the Kitt display we will need 6 of the LED bar graph displays, so in the worst case we need to be able to provide enough current to drive 6 LEDs. Checking out the data sheet for the LED bar graph display, we find that each LED typically draws 20mA (forward current). In practise, as little as 1 mA will light the LEDs, but they are fairly dim. 
  4. As can be seen from the breadboard photo, even one 10 LED bar graph needs a heap of interconnecting wire. Six times this would be a mess, which suggests that a Veroboard solution is not the go. We will need to layout a PCB or two.

3.0 Final Design


Addressing the issues raised by the prototype, I created a design which utilises two PCB's on top of each other (display on top). The display board schematic looks like this:


The associated double sided PCB layout is below. I used Fritzing to do the schematic and PCB layout. It is FREE and I highly recommend it for simple to medium level designs. They have an associated PCB fabrication service (in Berlin) which is fairly expensive, but for a double sided board like this with a number of via's, it was a good option.


We will cover the display driver board in the next article. Finally, a quick video of the prototype connected to AVA.



Thursday, June 25, 2015

Possible Approaches to Robot or Artificial Intelligence

With an engineering not scientific mindset, I am about to vastly simplify an extremely complex subject. With that qualification, there are two main ways we can tackle the problem of creating robot intelligence:
  1. Cognitive Robotics or Symbolic Modelling - attempts to create a model of the world in which everything can be represented by symbols. The robot controller can then parse these symbols in a manner similar to the way that a compiler creates machine code from a high level programming language. This approach suits computers, however reducing the world to symbols is a non-trivial task.
  2. Behavioural Robotics - creates emergent behaviours by having a number of prioritised responses to various situations. For example, a robot could have a behaviour which avoids walls and drops this would be a higher priority than performing a task like following a line or heading towards the brightest light. By layering behaviours on top of each other we create a system which can respond to a changing environment without having to specify what to do in exactly every circumstance.
Symbolic Modelling takes significant computing resources and isn't suited to a cheap micro-controller application. Given our constraints, this makes our choice of approach easy. Behavioural robotics is also the approach which is currently preferred by the academics (for what that is worth). More importantly, a behavioural robot can be built in stages and each behaviour debugged separately. This makes life easier and models how organisms evolve over time with increasing complexity.

The ultimate expression of behavioural robotics is to create artificial neurons which are not intrinsically intelligent but with enough connections create a neural network with emergent intelligence. We wont be attempting to crack that nut.

To design our robot intelligence we will use a behaviour diagram (from the book: Robot Programming : A Practical Guide to Behavior-Based Robotics by  Joe Jones), which looks something like the following diagram. This is a simple way to represent the robot control scheme. Input from sensors are shown on the left, these trigger behaviours which are manifested by the robot doing something (e.g. moving). The correct behaviour will be chosen by the "arbiter" based on priority.


We will develop AVA's behaviour diagram in a subsequent post.