Arduino Network Uptime Monitor with Twitter Updates

IMG_20140217_193610We’ve been looking for excuses to use our Arduino Ethernet shield in more projects recently; we had the idea today to see if we could get it monitoring our network servers and report the status of them to Twitter.

It was actually surprisingly easy; we had the Twitter posting code from the previous project and we found an Arduino ICMP library so that we could test a ping to the hosts and see if it was responding or not, we added this to our task scheduling code and the rest just fell into place.

Click here to read more..

How to do RF Communication between 2 Arduinos (and more!)

We recently ordered some very cheap RF modules online to test out with our Arduino’s that we have here, despite being very cheap products they do seem to work incredibly well – So much so that we thought they deserve an article on how to get them up and running and working with two or more Arduino’s (with example sketches)

First of all, the components you’ll be needing are:

You’ll need a basic understanding of the Arduino IDE and basic programming skills to implement the example code posted below.

Click here to read more..

Getting started with Flowcode 6

flowcode_6_logo_title2We recently attended the BETT 2014 show and bumped into Matrix Multimedia; they introduced us to the latest revision of their product, Flowcode 6.

We’ll be doing this in a two-part post as Matrix Multimedia kindly gave us one of their development boards to try out (ECIO28P PIC), we’ll be posting separately about what we’ve done with this in another review.

As we understand it Flowcode has been around for many years and has been going through it’s revisions with additional features with every version. There is a large community of users and a generous helping of documentation in the form of tutorials, videos and online courses.

Click here to read more..

Microcontroller Shootout – Arduino Uno

Arduino Uno R3The next Microcontroller we’re going to look at is the Arduino Uno R3 – This is a open source and low cost development board that has an ATmega328 and 14 digital input/output pins (6 can be used as PWM outputs) it also has 6 analog inputs. There is also a USB connection for uploading sketches (programs) from your computer and a ICSP header so you can program it directly if you wish.

We’ll mention it again; this isn’t being directly compared to the other development boards we’re reviewing and hopefully you can make your own mind up regarding what to use after this shootout series. We’ll be doing a summary of all microcontrollers when we come to the end of the Shootout.

There are various types of Arduino available; we chose the Arduino Uno due to the fact that we believe it’s the easiest to get started with and is also the lowest cost of the Arduino family – If you’re just getting started with programming microcontrollers then this would be an entry level product for learning and prototyping.

We’ll be running the same example as we did with the Parallax Propeller, by setting up the board and development environment and flashing an LED with code. Pin 13 is by default an LED actually on the board it’s self, so we’ll be flashing an external LED hooked up to a small breadboard.

Click here to read more..

Microcontroller Shootout – Parallax Propeller

PropellerThe Parallax Propeller (P8X32A) is a 32bit microcontroller with a difference. It contains 8 cores (called cogs) and can run different routines simultaneously. The propeller doesn’t seem as popular in the UK as it does in the USA but that’s probably because there are only a few places that stock it and it’s more expensive that the Arduino. It’s a shame really because it really is a great little chip. One other thing that may have caused the lack of adoption was the fact that it had to be programmed in a language called SPIN. Over the past couple of years however, Parallax have listened to the masses and have now provided a C programming environment for use with the Propeller.

Click here to read more..

Arduino – sorting array integers with a bubble sort algorithm

As it happens, I needed to sort an array of integers in ascending order and also find the minimum and maximum number from the array on my Arduino. I decided to knock up a quick bubble sorting function which you can find below.

Bubble sorting is probably one of the easiest and quickest (to write, not actually sort!) algorithms to produce in C. It works by iterating through the array of values comparing pairs and swapping them around if need be, it then performs the same action again until no swapping is needed. You can read more on the Bubble Sorting algorithm by clicking here.

The above Arduino sketch has debug Serial output which should look like the following one uploaded:

bubble

This code isn’t limited to the Arduino, there are no special function requirements needed and should work in any C based application. The only thing that you may want to change is finding the size of the array instead of having it static however I did not need this as I knew how many elements I needed.

Arduino based task scheduler/threading functions

ardIf you’ve used the Arduino before then you’ll know that any code you write in the loop() function is executed on every cycle. But what happens when you have code that needs to run at certain intervals? A delay() will just cause that iteration of loop() to hang and pause.

Arduino released a tutorial BlinkWithoutDelay which introduced the concept of checking the “uptime since last boot” and comparing that to make a basic function scheduler.

The code below basically does the same job, except it’s cleaner and easier to manage. This is by no means original, there have been hundreds of productions of this code, this is just one way to go about it.

The naming structure is shown below, instances of the Timer are prefixed with t_FunctionName to indicate this is a timer.

Instead of checking a single variable for the current milliseconds since boot, this will create a new instance of a structure that can be used to store timings for functions. This way you can easily change when to run a certain portion of code without digging through the sketch or remembering which variables contain the correct values.

The loop() portion of the sketch should be kept clean and only be checking the cycles of the functions from the structure. There should be no need to place any program code inside of the loop() function except for these checks.

This should provide the following benefits:

  1. Enable you to run code every [x] milliseconds or [x] seconds.
  2. Structure the program so that you know when code is running and being able to easily change this.
  3. Have a faster running program. e.g. if you know a portion of code is slower and delaying the loop() you can have this run on a larger interval so it isn’t executed as often.

This code is compatible with all versions of the Arduino and most likely other boards where the language is also based on C.

Fixing erratic LDR values

ldr

After working with a few different sensors hooked up the Arduino, I was experiencing some strange issues where as the value of the LDR would constantly jump up and down within a specific range. I am not sure if this is the quality of the sensor, but it was doing it for all of the LDRs that I have.

I decided that it needed some artificial smoothing in the code to get a useful value. See sample code below for smoothing out LDR values. We need to change the value from an erratic analog value to a digital percentage as an integer.

As you can see, the function takes two parameters samples and sampleInterval The samples is how many times it should query the LDR for the value and the second parameter is how long it should wait before each query.

Depending on the size of the LDR and quality, the min and max smooth value may need to be adjusted (550 and 1023) depending on the range you get back from your LDR.

The function will return an Integer between 0 and 100 depending on the amount of light.

Page 2 of 212