Sunday, October 28, 2012

Getting Started with AVR

About a year ago, I placed an order for a few extra PICs and at the same time ordered a couple ATMEGA328-PU micros at the same time.  I had only started to read about the AVR and this one looked like the perfect starting point. At that time, in the past, all of the Arduino boards were way too pricey for my cheap skate PIC background, but the simplicity of creating an AVR programmer drew me in.  

Now, it is worth saying that the two ATMEGAs that I purchased would have gone unused for a long time, possibly forever, if not for a bit of luck.  I had placed an order for some PCBs at ITEAD Studio and selected the "*Open Source And Get 2 More Additional Boards" option.  One of the extra boards they sent me was my own and the other was a Uno clone from JMN Electronics
In true good form, Joan placed her email address on the silkscreen.  Using that, I was able to contact her and get a BOM (had I a bit more experience with the Uno, I could have figured it out).  Since, the Uno uses such common parts, I had everything laying around to populate the board (including my aging inventory of 328's).

Now starts my frustration.  Of course I had the AVRs and a board, but I did not have a way to program the boot loader on them.  If you are like me, you are not too aware of your options and it is time to get Ghetto.  Thanks to Google and AVRProgrammer.com, I was able to whip together a FrankenProg (combine with AVRdude and you have something workable).  Yes, that giant hunk of glue is my concept of a strain relief and I have no intention of showing the nightmare that is the underside of the proto board.  I have to say that it worked perfectly and I was able to complete my clone Uno, but I am really dissatisfied with something like the above.  Maybe 10 years ago it was fine, but there is no support for OS's after XP and certainly not X64.  When I was reasearching programmers, I also came across the USBASP and it turns out they can be purchased on Ebay for less than $5.

As excessive reading would have it, I found that the USBasp by Lcsoft was upgradeable and works with Windows 8 x64. Ding!
The reasons I like this particular one are:
  • Inexpensive not cheap
  • Firmware is upgradeable via placing a second USBasp back to back and shorting JP2 on the unit to be upgraded
  • Two of them are $7 shipped to your door
  • JP3 is still available for slow programming (when you brick your chip)
  • 3.3V and 5V supply voltages
  • It is USB and is supported by AVRdude
  • The Arduino software can use it to burn a bootloader


In short, don't waste your time trying to build a programmer.  If you are coming from the PIC world, we could always build something cheaper than we could buy it (thank you high voltage programming).

Sunday, October 21, 2012

Sending Data Over Wireless Modules

Five years ago, sending data back from remote systems has always been a pain and required a good bit of engineering knowledge.  Fortunately, we can buy a set of wireless transmitter and receiver modules for $2.  A few details about these modules:


  • They operate at 433MHz
  • Data rates (baud) should be kept to 4800bps or lower (quality starts to diminish above 4000bps)
  • The transmitter can be powered with up to 12V, for greater range
  • Range is greatly increased by adding a 17cm antenna (straight piece of wire) to each module
  • The receiver will pickup a LOT of noise, so expect good and LOTS of bad data
  • Debugging data from the receiver is greatly simplified with a basic logic analyzer for $12
  • The receiver relies on the transmitter sending a preamble burst of data, so that it can lock onto the strong signal (vs background noise).  I recommend sending about 30 characters of 0xF0 before sending real data
  • Best practice is to utilize Manchester encoding for the data (I did not)
  • IT WILL BE NOISY. Be prepared to write code sift and sort out noise from data
  • ATAD == data input.  For the life of me, I cannot find out what this stand for.
A quick tip for starting out is to not even worry about the, "Odd" baud rate of 4000 and just start out with a standard UART rate of 4800bps.  One reason is that for debugging purposes, you can tap the RX port of a USB->TTL adapter to the ATAD pin and monitor the data going over the air.


Tuesday, October 2, 2012

Serial Communication with Bluetooth Module

With my temperature sensors working, the next step is to start getting data back to the PC/Mac/RPI (Raspberry PI).  Right now, data can be sent back via to ways:
  • RS232 via a standard USB serial port (and the supporting max232 circuit)
  • RS232 over Bluetooth
I reached one of the milestones in programming where I really needed to see real time debugging information.  The first step was to wire up a standard serial port and start dumping data to Putty (o'l standby).  Interestingly enough, on one of my shopping sprees I ran across a $9 Bluetooth serial module and I could not be happier.  I have scrapped my legacy MAX232 -> USB in favor of a Bluetooth module that accepts 3V-5V input (FYI, I think it outputs 3V signals).  It could not have been simpler to plug in the module, run GND, 5V and a line from the PIC.  A few minutes later, it is discovered on the PC and the serial port is added as COM6.  Nice.  Now that is one less cable between the PC and bread board.


The tricky part is that these devices default to 9600 8N1.  In reality, this is a very reasonable number for most applications.  However, I needed to drop it down to 4800bps due to the clock speed I am running.  The trick to that is that the BTM can only be configured via the terminal when the BT link is not active.  To do that requires connecting the BTM to the host via a TTL serial adapter.

Once communication is established, one item to watch out for is the firmware.  Some adapters come with HC06 (Linvor 1.5) and others come with HC05.  While, HC05 has more configuration options, I am not sure too many of them are useful.  To really dig into it, visit Byron's Blog.
Fortunately, there is a lot of information out there on configuring this BTM.  A quick Google for, "Bluetooth and linvor" will turn up a wealth of resources for customizing the BTM or you can download the manual.

Quick Start Guide:
  • Set Baud Rate - Sets the baud rate. Baud rate is set by an hexadecimal index from '1' to 'C'
    • Indexes are: 1:1200, 2:2400, 3:4800, 4:9600, 5:19200, 6:38400, 7:57600, 8:115200, 9:230400, A:460800, B:921600, C:1382400
    • Send: AT+BAUD<index>
    • Response: OK<baud rate>
  • Set Bluetooth Device Name - Sets Bluetooth Device Name
    • Send: AT+NAME<device name>
    • Response: OK<device name>
  • Set Bluetooth PIN Code - Sets the security code needed to connect to the device
    • Send: AT+PIN<4 digit code>
    • Response: OK<4 digit code>
  • Check Firmware Revision -Get The Firmware Revision Number
    • Send: AT+VERSION
    • Response: Linvor1.5