Monthly Archives: December 2013

C DIY Electronics Microcontrollers Programming Robotics

Quickstart guide to a basic PIC based robots – Part 1

While browsing for “goodies” on eBay I ran across a $9 robot chassis. How can you go wrong for $9? I haven’t built a robot since Talus my sumo Roomba, so I thought why not.

If you’re looking for something like the model I purchased, check out eBay and do a search for “Robot Chassis”.  Adam Fabio of TheRegnineer.com mentioned he has almost completed working on a product that is similar. I’m guessing you can look for Adam’s product at his Tindie Store once he has finished it.

.. Fast forward three weeks for shipping from China.

None of my sensors have arrived but you’ll end up wanting to customize you robot for whatever sensor pack you are interested in anyhow. With that said I haven’t written any code for handling any sensors and at the end of the day this robot is just going to drive straight forward all day long. You can follow the code at the repository I set up for it on github to get the latest updates at…

The software:

https://github.com/chasxmd/16F1509_Rover_Robot

The hardware:

I’m using the TAUTIC 20 pin PIC development board as it’s only $10 and takes care of the reset switch capacitor and comes on a nice plug-in board if you solder the connectors the same way I did. Use whatever you like but notice I’m using an internal oscillator so you don’t have to worry about getting a specific development board or having a crystal.

I’m also using the Pololu Quick 2s9v1 Dual Serial Motor Controller which is cost me $25, a little on the high side, but I had one from another project so I’m just re-using it and it makes life a lot easier for development.

Check out the photo at the bottom of the post for the basic schematic.

Beginners:

If you don’t already have MPLABX you’re looking at an upwards battle. However if you don’t mind watching a few YouTube videos it’s not up a creek.

1. Download and install MPLABX and the HI-TECH C compiler.

2. Start a project within MPLABX; selecting PIC 16F1509 and choosing the HI-TECH compiler, and create a main file.

3. Copy my code off the github site and drop it into your main file and compile.

You can download the free version of HI-TECH C and MPLABX which is also free. They are both obtained from http://www.microchip.com. MPLABX is an IDE (integrated development environment) which means it’s a program for programming, compiling and loading your software. HI-TECH is a C compiler which works with MPLABX. There are other programming language options such as BASIC and even assembly (I use assembly most of the time). I don’t know of any free BASIC compilers but I’m guessing someone has one. Google might be your best friend if  you’re looking to go that route.

If you don’t have MPLABX you probably don’t have a PICKit 3 (or other hardware programming tool). I like the PICKit 3 because it will program all the newer Microchip PICs and it’s just about the most affordable tool for PICs. PICKit3 comes from Microchip or Digi-key. There are alternatives.

The Build:

It took me about 30 minutes to put the chassis kit together last night. It was pretty obvious how it went together which was good because there were no directions. The encoder wheels don’t really attach other than compression, I see issues with that if I end up using them… that’s what you get for $9?

The code I put together this morning in about an hour or two after reviewing the manual for the motor driver online; you should also review this document. The idea with the code was just to test the motors and motor driver. I also selected a high/half/normal speed which you can adjust for your motor’s needs. I believe the highest speed setting you can select is 0x7F, I chose 0x4F for my high speed based on my anticipated desire. Adjust as needed.. but keep in mind your low speed should be set so it doesn’t stall on carpet or whatever you want your robot to be driving around on.

That’s about it for now. Once I get some sensors in I’ll add them and then write the code. I’m still new to C programming but I felt it was a better choice since it seems most popular; I usually write everything in assembler. Check out the photo I posted as it has a basic layout of the circuit and how I set mine up on a breadboard until I receive some prototyping PCBs I ordered.

First step of my cheap chassis robot build... getting the motors turning.
First step of my cheap chassis robot build… getting the motors turning.

 

…. to be continued

Electronics

My @digikey #digiwish arrived!

Digikey selected my #digiwish as one of their daily winners! I asked or a new 3M mat for my work bench and it came out looking better than I has hoped for; Thanks Digikey. Unsolicited recommendation: About 90% my breakout boards and specialty items come from Sparkfun or Tindie, but for all my parts and other items such as my Microchip PICkit 3, I shop at Digikey. They have good pricing and a lot of times I get my order the next day with the cheaper shipping despite being half way across the country.

The before and after photo! (left to right it’s actually after and before)

I was a winner of #digiwish from @Digikey this year. I wished for a new mat for my workbench... I knew I wouldn't buy one myself. Thanks to Digikey my bench has a fresh new look!
I was a winner of #digiwish from @Digikey this year. I wished for a new mat for my workbench… I knew I wouldn’t buy one myself. Thanks to Digikey my bench has a fresh new look!

 

Hardware Hacking

The @JohnS_AZ Blogger Guilt Trip

There is a lot of content out on the internet… a lot.. but it’s amazing how much of it you can burn through on a day full of programming. I started picking up a couple more podcasts just because I’ve been running out my normal subscriptions. I started listening to ZombieTech; a podcast made by the @tymkrs… entertaining and informative. I finished listening to Episode 003 with John (@JohnS_AZ) this afternoon and it really made me think about my content as a blogger. My blog isn’t intended to be a “build this” or “this is how you do it” type of blog but I feel John’s message still applies. If I come along a blog or project site of some sort, more than not, the media describing the project is usually lacking. In the case of YouTube videos, sure.. we get so see the LEDs blink, but there is usually no circuit review, code provided, or schematic provided in PDF. John mentioned how a video of circuit explanation would be helpful for those who want a little more information in line with something like a blog entry that includes some code and description.  I whole heartily agree with him; I’ve also found myself wishing there was more information in an article countless times. So now I have a little guilt now over being a very sloppy blogger. I can do better, even though I’m not writing articles to generate content, nor am I suggesting readers might be interested in building whatever I am; regardless, I’m demanding of myself to do more do-diligence before posting… maybe comment my code better and certainly it’s easy to do some small uncut YouTube videos… even if it’s rocked out on the iPhone. Don’t get me wrong though, you won’t be getting schematic out of me much because I usually don’t build-by-schematic. I will offer you this though: If you’re looking for some content on older blog posts I’ll be happy to go revisit the project and offer an update. Most if not all my blog posts are of snippets of information that are generic enough that you can re-use what I’ve done in something you’re working on. I don’t think I’ve actually posted any “complete” work to date; I imagine that’ll be a rare day when I do.

So thanks for giving that interview John, it was definitely insightful. I look forward to seeing what your HackersBench.com site turns into.

Analog Electronics Hiking/Backpacking Microcontrollers

Wireless Plant Soil Monitoring: The Beginning.

I saw a little probe for monitoring soil on eBay.. $1.69 and free shipping.. purchased! Okay.. its a lame little PCB with some electronics I won’t use but still, nifty. I didn’t have much on my plate today and I was pretty sore from a solid hike yesterday so I was riding the bench seat today. I built a little front end circuit mated to a little MCU built on a Jayson Tautic 8 pin dev board with a 12F1840. It dumps serial out to a $3 433Mhz transmitter when the soil is low on water (still need to write some sleep code).. on the other side the receiver and well I don’t know yet. Honestly I started with thinking about a XPORT but I haven’t made my mind up.

Work in progress.... watching dirt dry.
Work in progress…. watching dirt dry.

 

So, a funny side effect: My wife was frustrated that she couldn’t get our wireless Christmas lights to turn on. Heh, well “Ooops!”… shocker, I had to turn my circuit off. So next I’ll work on the receiver side. I’m thinking my poor plants need to text message me when they’re thirsty? I’ll drop code later when it’s more complete.

And yesterday! I hiked past this pretty awesome frozen water fall (and two others) on my way up to Lake Serene. Last year we got stopped by a nasty avalanche field.. this year is was just solid ice. Thankfully I had my Kahtoolas.

forwa

Analog Electronics

Preparing Enameled Wire

I am doing some experimenting with some small signal magnetics and a thought crossed my mind to ask the super-cool @tymkrs IRC channel gang if I was missing the boat on stripping enameled wire. Turns out I was….

Warning: I will not be held responsible for wives who are upset about missing emery boards.

The winner was the emery board. My wife might have to donate one to the cause.
The winner was the emery board. My wife might have to donate one to the cause.

The conversation:

<chasxmd>JohnS_AZ, is there a magic formula to removing the enamel off magnet wire?
<tautic|mobile>Stupid traffic
<mgburr|work>good exacto knife and scrape, or heat to 400f
chasxmd: hit it with your iron that is set higher then the melt temp
thanks for the tips, I've always gone exacto knife and felt there had to be a better way
<johns_az>chasxmd: I always steal one of Lisa's emmory boards. :-)
<johns_az>fine sand paper works well.
- scratch quit (Ping timeout)
<mgburr|work>all of the above

So I put these to test! I’m using 30 gauge wire that’s less than 10 years old and was redistributed by GC electronics.

Soldering Iron: Free air and solder pool.

Sanding: emery board and 220 sand paper

Exacto-Knife scraping.

Not tested, but possible future ideas: Blow torch, actually googling to see if there is a tool the industry uses.

So scraping takes a while and it leaves small strips that you end up having to sand or rotate a 30 ga wire and get lucky? On 30 gauge wire, forget about it.. a waste of time.

220 sand paper? probably a lot better on 18gauge+ enameled wire but for small wire it was a hassle and took way too much time testing the conductivity and making sure I had gotten at least almost all the enamel off.

The two reasonable methods for my wire were my wife’s emery board and the soldering iron.

The emery board was the shortest method. I removed a 1/2 inch* section of enamel in just under a minute**.

The soldering iron was looking like a bust because I was free-air rubbing the wire to the tip of my Weller soldering station with some fresh solder on the tip. At 1:15 I hadn’t made a dent in the enamel. I trend grabbed a piece of copper clad board and added a little solder and rubbed the wire with the soldering iron and it turned out okay.

* I live and work in the USA. I use measures of units that I was born and raised on; It’s not lost on me that this is inconvenient for you non-US persons.

** I wasn’t cracked out on caffeine and I was just taking a leisurely relaxed pace through this process.

ASM Electronics Hardware Hacking Microcontrollers PIC Programming Time

WWVB Time Signal Generator Test w/ HEX

[Edit: I’ve added the .asm code in the “Code” page in the menu above. Below you can find the .HEX file for easy programming]

A successful test on my WWVB signal generator. I’m going to shy away from calling it a transmitter because I don’t think there is any allowances for any broadcasting on 60KHz, so to stay legal I would imagine you’d need to conform to part 15, shield everything, use an attenuator and dump the signal into a shielded box with the clock? I somehow doubt the FCC checks up on sub-mW transmissions on 60KHz though.

The concept is simple, 1 baud rate transmission of a 60 frame packet. The amplitude shift keying (ASK) system WWVB transmits is recreated using a CMOS CD4066 switch. Dump a 60KHz sine wave (keeping in mind maximum input/output signal specifications) into one of the switch ports. Use the output on PORTB.0 of the PIC to control the switch and the other side of the switch goes to you device under test (I used a couple feet of wire as an antenna and just placed the wire in the neighborhood of the clock receiver). It’s a no brainer. Check out the NIST site on WWVB if you want more details. I’ll probably re-port the code to a 12F629 when I get my new PICKit3 in and I’ll likely build a board with a 60KHz generator.. maybe I’ll even sell it on Tindie if I’m feeling ambitious.

The Test! I was getting my ass kicked earlier this week as my circuit was not working and it seemed like everything was just right. It did force me to really tweak my timing to make it within my range of error on being able to measure the exact pulse widths, I don’t know how precise it has to be but I assume that’s up to the algorithm decoding the signal. Turns out it wasn’t my code or circuit.. My $15 Fred Meyer “black friday special” atomic clock doesn’t work. It won’t receive the real WWVB (set up aligned with Boulder, CO away from electronics, blah blah). I was getting the proper signals out of the module, so I yanked the module out of the clock and hooked it up to a receiver designed by N0QBH. I mirrored his project here. He has a website for the project here. I used his schematic, ditched the need for the LCD and just grabbed my data off the RS232. Done! You can see a before and after output screenshot in the photos below.

My WWVB signal generator code (HEX) for a 16F628A is found here . Is it lame of my just to provide the HEX? yeah…. but all you need to do is hook up PORTB.0 to switching input of a 4066 with a signal generator feeding a 60KHz sine wave and you’re in business. (And a resistor pulling /MCLR (PORTA.5) up as well if that wasn’t obvious? I’m using the internal oscillator; no xtal needed).  You are stuck with my fixed date of course.. which is why you want my assembly code right? No problem. Just ask… really (comment or e-mail). I don’t want to post it because I don’t really like comment trolls. This code is super BETA but at an acceptable starting point. Lots of opportunity for optimizing it as well.  Why didn’t I improve on this code? Because I don’t need to. I’m just using it to test receivers I’ve purchased from the UK and I’ll be working on a project with those in a little while.

My time/date is static here is a snippet of the main line code:

    CALL    MARKER                      ;MARKER FRAME REFERENCE BIT
    CALL    ONE                         ;40min
    CALL    ZERO                        ;20min
    CALL    ZERO                        ;10min
    CALL    ZERO                        ;Reserved
    CALL    ZERO                        ;8mins
    CALL    ZERO                        ;4mins
    CALL    ONE                         ;2mins
    CALL    ZERO                        ;1mins
    CALL    MARKER                      ;MARKER 1

… and so for some photos

signal from PIC before ASK modulation accomplished by switching a CMOS CD4066 with a 60KHz sine wave from a frequency generator.
signal from PIC before ASK modulation accomplished by switching a CMOS CD4066 with a 60KHz sine wave from a frequency generator.

 

WWVB receiver module removed from clock

The clock with the module removed, luckily they printed the pin diagram on the board. 5V, Gnd, PON, and TCO

WWVB Signal Generator and Receiver on Breadboard

Both the generator and receiver on the breadboard. The transistors form the RS-232 driver for the receiver.

Before and after on the RS232 output of the WWVB receiver
Before and after on the RS232 output of the WWVB receiver

 

Electronics Microcontrollers Time

WWVB Transmitting Generator/Simulator

[Edit: a follow up post includes code]

I owe it to my PICKit3 to give it a proper obituary.

PICKit3-BUR123467218, 1, Side-kick PIC programmer worked long and faithful.  Assisted in countless re-downloads to facilitate troubleshooting poorly written software.  PICKit3 met it’s maker when inadvertently electrocuted with 12VDC. Leaves behind distraught hobbyist programmer companion. You’re gone but not forgotten.

I was finishing up final touches on a 16F629 8 pin PIC that was generating a WWVB broadcast to have a piece of test equipment which will help me write code to receive WWVB ASK time/date information. I accidentally plugged my breadboard into 12VDC. Even with ninja speed I couldn’t get it unplugged in time. The 16F629 and PICKit3 were dead in milliseconds. I had to dig out the PICKit2 to save my weekend. Turns out the only PICs I have that will work with the 2 is a PIC16F628A and a 18F452. So I ported the code to the F628A and tested away on it. I have the code down to what I think is nearly perfect, with nearly perfect timing. I have tapped into the TCON output of a 15$ atomic clock I purchased recently. The clock I receiving the data fine, but it won’t sync for some reason. Two nights in a row with no synchronizing to the actual WWVB so I’m wondering if my 15$ clock just doesn’t work.

I’ll post the code later when I am sure it works. The receiver is on its way from the UK. That’ll be a project sooner than later. I was considering making a breakout/dev board out of the generator but then I saw a seller on Tindie has done that but also married it with a RTC.

The programming for the WWVB was pretty straight forward. Just look it up and capture it from NIST, no reason to repost, but here is a link to the PDF.

EDIT: Ugh, I got retweeted a few times so now I have that I-didn’t-post-code guilt. *IF* you want the code: comment, tweet or e-mail..  I’ll give it to you. I don’t want to post it for free download until I know for certain it’s reliable. I hate to steer someone wrong. Let me know if you want the .HEX file or just the assembly file and you can compile it yourself. I’ll even consider pre-programming a 16F series PIC if you really want it.

Right now the 60KHz transmitter is a function of my signal generator but the parts are on the way to build a solid low power transmitter. Anyone interested in the whole thing on a PCB?

My new PICKit3 and a couple goodies are already ordered along with some goodies…midweek until I can get back to work I suppose.

“To be continued”.