The Electronics Page

The home pageup.gif forward.gifWeekend Workshop forward.gif The Propane Foundry forward.gif Learning CNC forward.gif Kart forward.gifPhotography forward.gifRoadster

  
I have been involved in electronics in some form, from early childhood, either playing with the electronic educations sets, to becoming a radio ham to working in the radio field.  I also like to build things from simple oscillators, kits, mods to radio equipment to micro controller systems.

Recently I have used an old 8051 SBC to interface with train radios to allow for calibrations and testing away from on-board control systems.  This got me back into assembly programming with the 8051 architecture.  Whilst my interest was peaked, I looked on the Internet for small project boards using the C programming language.  The idea is to learn C and have fun, we all like to see results and "Hello world" is getting a bit lame now.

8051sbc1.jpg 8051sbc2.jpg

With the ever increasing use of the Internet and IP networks in general, I decided on an Internet style controller. Someone suggested the tuxgraphics SBC with network connectivity and analogue as well as normal I/O pins.  Here is a link to the www.tuxgraphics.org web site. Well recommended.

tuxbord1.jpg
 

So I ordered a surface mount board and ISP programming lead. I downloaded the Atmel studio4 package, WinAVR and after some help from the AVR freaks web forum, away I went.  Progress is slow, but fun, most of my books on learning C are all dealing with computer based ideas, dealing with strings and output to screen.  Not always what you want when dealing with SBC's

The project is to have a internet pinger, very simple battery powered, unit where I could programme it's own address and that of the device to ping.  Then have the board display a few simple things such as the time to response and condition of the battery by using standard LED's on the I/O pins.

The time to response would be shown in ranges, with the 1st LED being less than 10 ms response.  2nd LED 11 to 20 ms. 3rd LED 21 to 30 ms and a 4th LED to 40 ms.  Then use a three LED's to indicate battery charge, green being fine, orange less then 30 minutes use remaining and Red for low.

The tuxgraphics.org website has a wealth of downloads, small programme ideas and software to do much of the internet work I needed so it was a good start.  To have to learn how to control the AVR from the basics would mean I would never start, much cleverer people have done that for me.

I have added my own client, ping & receive response function calls within some of the routines. Built up main.c, not quite to any standards but the results are here for all to see and comment if they wish.  Perhaps my ramblings can also inspire, if I can, you can!

Link to Pinger software completed 04/10/2008.

Link to Pinger software completed 09/10/2008.

Link to Pinger software completed 30/11/2008.

There are a few settings of note, most from the tuxgraphics software

static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x10,0x24}; // set your device mac address here
static uint8_t myip[4] = {192,168,0,20}; // set your device IP address here
static uint8_t destip[4] = {192,168,1,10}; //Set the IP address of the device you wish to ping
static uint8_t gwip[4] = {192,168,0,1}; //Set the IP address of your gateway to the outside world!

Generally these and the rest follow the tuxgraphics web server version 2.11 and the NTP clock.     pinger1.jpg

An explanation: -

It retrieves the mac address of the gateway, then will move on to get the mac address of the destination device by sending ARP requests.
If there is no response within 5 "trycount" attempts, it will then direct a ping via the gateway address and look for a response.  Again if no response within 5 "trycount" Pings, it will revert back to own segment ARP requests then via the gateway repeating it self ad infinite.

There is also a  swap  variable added to some of the function calls in ip_arp_udp_tcp.c and ip_arp_udp_tcp.h. This has allowed me to ping direct to the device mac address, or, ping via the gateway mac.  Similar the ping response function uses this swap function  to determine an incoming packet directly from a device on the same network or via the gateway.

net.h has also undergone a few changes, still trying to stick with the same format as before but adding a few more ICMP positions and values.

The ICMP section of outgoing ping has and incrementing sequence number to ensure a valid test on the response to the last one sent.

Once it has the packet responses it keeps looping sending out a
packet at interval "step".  This step value will be read and checked for a range of values to determine which LED to light at a later stage  this will be done on getting a valid ping response and prior to resetting step = 0.

My code format is apparently frustrating to some, I am positive once I become familiar with C programming, I will fall into one of the major formatting structures, but for now!

The switching on and off of the relay drive is still there as before with the difference I have added my name in the credit line.  I have endeavoured to keep the functionality of 2.11 all there, that way the programmes will be of more general use.  As the diodes and code for the display is added, so I will add further code to this page. and try to keep at least 3 versions available.

01/10/08 Have added a variable called "interval"  setting the period between ping requests and finding various mac's, the LED's are fitted to my board as well.  I tested it to various sites on the web to show tat the range does in fact work.  Lastly forgot to mention that the client ping request change have its TTL set to it's own value still leaving the web software TTL as it was.

03/10/08 Have programmed the ADC in single shot mode, just using 8 bit mode at present but will get to 10 bit soon.  Added a few more variables such as "batlev"  for the ADC reading and "battchk" for the timing loop (10 sec).

Known bugs: -
To be done: -

  1. Code and hardware for LED's (Ping response times)  Now done range is initially 0 to 24, 25 to 49, 50 to 74 and 75 to 100 ms, longer & no leds on.
  2. Code and hardware for battery monitoring. Now done but needs changing to 10 bit rather then 8 bit resolution, beginning to understand more as I figured it from the datasheets and it worked. My word does Studio4, WinAVR/GCC make it easy, made batlev uint16_t and just use batlev=ADC; and I have 10 bit resolution.  Soooooooooo Simple.  Taking a while to box up the unit and stop me shorting wires out with my birds nest approach.

pinger2.jpg
This certainly looks better! 
Internal battery, LED's for status on top. 
Charger socket, switch and RJ45 to the front

  1. Stick the information on response times and battery state into the code/text area of the Ping request so it can be pulled out by another application.  Now done, 091008.  Bit of a bodge and one thing that may well be improved in the future. See below for more
  2. Add an LCD to display ping response times TTL and battery state. 121008  Done as a separate programme with another TUX board see below.
  3. Allow changing if IP addresses via web (Look at the tuxgraphics NTP code for examples).
09/10/08.

I added the Response time and battery voltage into the data area of the ICMP section in the early hours, looking back on how I have done this, I believe could be done a lot better.

It has taught me a few things by making me read the Win GCC information.  Such as using PROGMEM is placing some of the long text strings into the flash memory, the itoa( ) function  changing the hex from the ADC to decimal and then to ascii format.  I would prefare it more if there was a printable format such as a pdf of the information to download rather then web based pages needing printing, I find that much easier to read a book at the side then flick from screen to screen when trying out new things.

I have changed the source file ip_arp_udp_tcp.c to add the special bits I needed, rather then work this out in main.c and pass the variables though to the TCP/IP routines, bad practice I guess?

It took me a while to figure out how I could display the 10 bit ADC as a true battery voltage.  I have a very basic resister divider network across the battery to the ADC input pin that has around just over an 8:1 ratio.  So 8 volts gives just over the 1 Volt at the ADC input, with a 10 bit ADC and 1.1 Volt reference the value is 0x3a2.  When trying to work this back to the battery volts would be displayed the mathematics would be ADC10 * 1.1 * 8/1024 or ADC * 8.8/1024.  But I could not do decimal sums as everything is Uint16_t.  If I wanted 6.25 volts I would have to multiply by 10 and adjust later.  I could not do this with int values as the max is 0xFFFF or 65,535 and when I multiplied the top line I have values of  81,840 0x13FB0 which is a lot more then the uint16_t can hold and can later translate via itoa( ) to ascii format.  So I settled for a 6.2 format and cut the sums down to ADC10/116 and still move the decimal point later.

I have also made this my version 1.0 release of software, why not I thought.

12/10/08

I once again started with the eth web interface software 2.11 and added sections from other tuxgraphics projects.  I added the lcd.* files to the list of source files and with the previously modified files for the Pinger was able to pull the response time, battery volts and sequence number from the 32 bytes of ping data.
The hardware is as per the NTP clock in this example so when I get bored it will go back as that.  I learnt a few things about strings along the way, just hope I can remember them when I need them.
respond1.jpg

It is very difficult on a home network to get any delay at all to be shown, so I will have to wait until I can connect it across a much larger network.  It does work as when I sent ping's to the outside world the response times and led's on the box would change as conditions changed out there.  The Batt is the indication of internal battery and lastly the count is the sequence number of the ping, that way I can tell at a glance if it is incrementing and therefore still in touch.

respond2.jpg

Bought and fitted a 4 line by 20 character display in blue, looks quite good, built it into a box as before to stop damage to the electronics.

Link to Responder software completed 12/10/2008.

30/11/08

Found a bug when trying to set the gateway ip and the destination IP to be the same.  For local subnets only, updated and added above. Called it Version 1.0.1



The web page is copyright me but the software is GPL version 2, as  I understand it?

If you wish to contact me, please E-mail by clicking on the following link and then remove the "spamtrap" Email


© A Hodgson