Ar2uino Digital PSU – 6

 

We have so far built and TESTED the digital part of the Ar2uino Digital PSU and we have verified that we can print to the TFT display and set the two DACs to voltages between 0-5V (or VCC). Combining an Arduino with a display like this is a very handy platform for a lot of different projects – by adding different input/output capabilities to this and a bit of software you can make almost anything! 🙂 And that is just what we are about to do – a PSU! You can see most of the analog parts in the picture above. Only a few capacitors and the power components; Darlington transistor and 5W 0.1 ohm resistor are mounted elsewhere! Does not look overly complex, eh? 🙂

The analog part

This is where we ‘slide over’ to the analog part of the Arduino Digital PSU. What we want to do here is to make a sort of the ‘voltage regulator’ or ‘amplifier’ to achieve the voltage and current output that we want. To do this we will be using an op-amp CA3140 for adjusting the output voltage to the one we have set with the DAC. We will also use this CA3140 to keep the current below a set threshold! To find out what the current current (Yes, it is correct!) is we use another op-amp, a LT6105 that is a special ‘current sense amplifier’, that will give us a voltage that is proportional to the used current. Lastly we use an ordinary op-amp LM358 to react when this ‘current voltage’ is higher then the set current limit and pull down the output voltage through a special strobe input on the CA3140. Check out the block diagram!

NOTE: As I write this blog in ‘sort of real time’, while I work my way towards the goal, the design has NOT been tested in full yet so I am quite excited to see if my design will work as I intended! When I have built the design and done any necessary modifications I will naturally update this blog of the changes as well! AND hopefully remember to remove this comment! 🙂

Well, we start by placing the active components CA3140, LT6105 and LM358 on the right hand area of the perf board as can be seen in the big picture on the top. I have rotated it a quarter turn anticlockwise just to show it better! We will need three trimmers. One for zero adjust of the CA3140, one for output voltage step trimming and one for current limit step trimming! They will have to be placed so they can be adjusted – either from the top (with the case lid off) or from the bottom (through holes). The latter is if you want to be able to adjust these and not have to remove the top part of the case! As we are using a digital setup for this we can also make some adjustments and trimming in software – if necessary! We will also need room for a few other components like resistors and capacitors!

Decisions

Before we go on with adding the resistors we will need to make some decisions! First of all is what the smallest voltage step should be when setting the output voltage. That will at the same time limit the maximum output voltage. I intend to use 10mV as the smallest step. That will allow me to set an output voltage up to a max of 40.95V – because of the 4096 steps that the 12 bit DAC can give! Remember  that the DAC gives around 5V at its maximum – that gives that we have to have just a little over eight (8) times amplification of those 5V to get 40.95V. We will use a trimmer as part of this voltage divider that we will use for the CA3140 so we can trim it for exactly (or as close as we can) to 10mV steps! Remember that the 40.95V is only the maximum that it can be set for! The input voltage (max 32V – depending on the LM358) will decide the max output voltage! This also means that you can easily supply it with different voltages and get different capabilities from the Arduino Digital PSU!

We need to make the same type of decision for the current. The smallest current step that I feel would be interesting is 1mA and that would give a maximum current of 4.095A which also can be expressed as 4095mA! Again this is just the limit of what can be set! The maximum input current will naturally limit our maximum output current! We are using a 0.1ohm current sense resistor that will generate a voltage of 409.5mV when 4.095A is passing through it! To balance that against the 5V we get from the DAC we need to amplify our 409.5mV a little over twelve (12) times! Again we will use a trimmer as part of the voltage divider for the LT6105 so that we can set the steps to be exactly 1mA steps!

The third decision is the actual maximum voltage and maximum current we want! How much of the available range we will use all depends on the input voltage and input current! In both cases it means that I will not be using the full range of the DACs with my 19V and 2.4A input! (See below!) But I think that the advantages of having “easy” smallest steps outweighs the advantage of even smaller steps – at least for me! It will also give us greater freedom when we pick the input voltage and current! Depending on the choices we make we can easily just supply a higher voltage or a higher current and the DPSU will handle it! We will probably not use 10mV or 1 mA very often as we normally will not set voltage or current that precise! We can also take the road to smallest possible steps and limit the max voltage to just below the supply voltage – and get albeit uneven but the smallest (and most precise) settings!

All the above reasoning and calculations can naturally be made for the other maximum voltages/currents and for other smallest steps! You might even make it switchable and have several settings! We will discuss the maximum current towards the end and what you can do if you need to increase it! It is not that easy to increase the maximum voltage so I will not go into that!

Another decision to make is what kind of input supply you will use! I have already mentioned my decision to go with an old portable computer supply – 19V and 2.4A. (See picture!) It is very handy to offload all the “conversion” from mains AC voltage to a suitable DC voltage to that small box! I can at any time swap this for a supply with higher voltage and current – as long as it is below 32V and 4A. Anything that delivers over 9V can be used – as long as it is sufficient for you! In case you are troubled by the radio noise from switch mode power supplies you can easily use a transformer, rectifiers and proper big capacitors instead! 🙂 Just remember that the maximum usable voltage depends on the components ability to handle the voltage. In our case the LT6105 and CA3140 will both go up to 36V but the LM358 will only handle 32V. In case you need those last volts – just swap the LM358 for another op-amp which can handle the voltage! (Like another CA3140!)

Placements

Having placed the active components on the perf-board and decided on the smallest steps for voltage and current according to above we have to fit in 6 of 1/4 W resistors, 3 small ceramic capacitors and the 3 trimmer on the board as well. There will be some other components added off-board! I have calculated the resistors to give a reasonable range of adjustment and at the same time give a reasonable precision with the trimmers. You can see how I placed them in the picture on top – note that I have turned the picture a quarter turn anti clockwise! I had an issue with space so one of the trimmers is a low profile multiturn trimmer so that it can fit under the edge of the display board. No other reason! You could have all as multiturn trimmers – especially if you want to have greater ranges to trim over and/or want more ease in precise adjusting – but it is not necessary I think! (We will see if I will have to change this when I start adjusting …) There will probably need to be a few more resistors for feedback adjustments – but we will see about that very soon …

According to above decisions the resistors picked were: 180k, 22k, 2.7k, 1k, 2 x 300 ohms. Trimmers: 100k, 2.5k and 5k. Capacitors: 0.1uF, 56pF.

Next time it is ANALOG TESTING TIME! Hurray! 🙂
But also a bit scary …

See you soon again!
/Sfenn

Ar2uino Digital PSU – 5

Next up is to test the two MCP4725 12 bit DACs! First of all you have to find the I2C addresses to be able to communicate with them. You can select one of two available addresses by pulling a special pin on the DAC low or high. If you set them like me by soldering over the Address bridge points – the left one to VCC and the right one to GND (See the picture above!) then their addresses will probably be 97 and 96. Or if you, for some reason, want them in hexadecimal: Hex=0x61 and 0x60. Easiest is to find the addresses by scanning the available I2C addresses. That is nothing like rocket science – just sweep the address within the range 1-127 and se when you get a response!

The I2C bus allows for addresses 0-127. According to I2C-BUS several addresses are used for special purposes so only 112 addresses are actually available! 0 is reserved for “broadcasts” to all devices on the bus at once. 1-7 and some other spread out addresses are also reserved so what remains are actually only 112 addresses within the 8-127 span. Code for scanning the I2C bus can be found here!

After having found the addresses to be used to access the DACs we should test to see that they work as we expect them to! Better to be safe then sorry! We do this by connecting a small load of around 100k and a voltmeter across the output of the DAC and GND and sending it commands to set the output voltage (Code below!). The MCP4725 DAC uses its VCC as a reference for maximum voltage. So in this case where we have an ideal VCC=5V the output will be in the range 0-5V or whatever voltage we use as VCC. In real life it could be 4.93V or 5.12V or anything near – depending on the tolerance of your sample of voltage regulator.

DACs Testing

The control of the DACs is through the “Wire” library and as the MCP4725 is such a simple component we do not really need any libs to control it – except for the “Wire” lib for the I2C communication. 😉 I have written a small testprogram that will output 20%, 40%, 60%, 80% and 100% of the supply voltage and wait 10 sec between changes so you will have time to measure the voltage at the output pin! Measure the voltages and compare to what it should be! Be sure to compare the output to the supply voltage – at the MCP4725 VCC pin! Then all you have to do is the percentages! Be sure to run it for both DACs by changing the “61” to “60” for the DAC_ADDR. Mine were very good – with a max of 12mV deviation from linearity!

NOTE: If you power this (while building and testing) through the USB cable then you will probably have a much lower supply voltage than from the 5V voltage regulator as seen below! This is due to losses in the USB cable. In my case the supply voltage from the USB cable was only 4.71V! Nothing to worry about during this testing! We will be testing it with the proper 5V regulators later.

Download MCP4725 Testcode!
As usual, clicking the button on the left to bring up a new window with a text only PDF.
Copy all of the code and then switch to your Arduino IDE and paste it in a new empty window.
Compile and upload to the Arduino! Ready!
(This roundabout way via a PDF is because WordPress will not allow text- or ino-files!)

Voltage regulators

As long as the supply voltage to the DACs is stable it does not matter that much what exact voltage it is! The MCP4725 can handle 2.7-5.5V. They are 12 bit DACs so they will offer 4096 steps (0-4095). That means that each step of output voltage will be 5/4095=0.001221V if we have exact 5V as our VCC. That is just a little over 1.22mV per step. Later in the project you will see that by designing the following output stages of our DPSU for having a maximum output setting of 40.95V* we will get a very neat step of exact 10mV. We will be using trimmers to set the exact ratio so do not worry about the exact voltages now!
* This is only the maximum setting that the DPSU will be able to set!

How high voltage the DPSU will actually be able to deliver depends on its input voltage! If you feed it with 25V it will be able to deliver a maximum of a few volts below 25V! And so on to the maximum input voltage of around 32V – that is the max voltage that the used ICs can handle! I myself intend to use a power supply from an old portable PC. If you know that you will always stay below 20V then you can actually have 5mV steps instead! More about this later!

To power the digital electronics with a stable voltage and to offer two fixed output voltages two voltage regulators with 3.3V and 5V output are fixed to the bottom of the case using it as a heatsink. In my case it is a L7805 5.0V regulator (to the right in the picture) and a LM317S variable voltage regulator set for 3.3V. You can use any voltage regulators that you have laying about as long as you can get 3.3V and 5V from them! Later tests will show if it is a good idea (stability wise) to allow the supply voltage used for the DACs to also be used as an external supply … with its variations in load!

A small perf board is used to hold the resistors that are used to set the output voltage and the in-out capacitors. I was given a number of surface mount LM317S from a friend (Thanks Erik!) and I made a small angled aluminium piece to hold it pressed against the bottom! (See picture above!) Maybe I am over-careful but I use a spring washer to absorb any thermal variations in size. They are just connected as in the datasheets with capacitors both at input and output! If I were to give you one piece of advice – except for wearing sun screen – it would be: Use a slightly bigger perf board than I did! 😉

The only unusual construction detail is that I bent the pins upwards and soldered the regulators from the bottom side – to give the perf board some distance to the bottom of the case. NOTE: Also remember to use silicon pads to isolate the regulators metal parts from the metal case!

This means that we are finished with the digital part of the Ar2uino Digital PSU! 🙂

Next time we will start with the analog section!

See you soon again!
/Sfenn

Ar2uino Digital PSU – 4

After testing that the Arduino Nano worked with the pass-through USB connection we are ready to connect the 2.4″ TFT Display. As the display is a 3.3V device and the Arduino Nano is a 5V device we will need to convert the interface voltage back and forth between those two voltages. There are many ways to do that but a 4 channel bi-directional level converter ($0.35 if you buy a few on Ebay) will do the trick very easily! Connecting the display to the Arduino is actually 5 signals – but there are 4 signals going to the display and 1 signal from the display. That last one coming from the display will be 3.3V but the Arduino can handle that – so it will not have to be converted! That leaves us with 4 signals that we want to route through the level converter!

A word on the Arduino Nano: We are using this in the standard 5V configuration. If we were a bit more adventurous we could have run it by 3.3V and skipped the voltage converters. But running an ATmega328 at 16MHz is just below the guaranteed working voltage for that frequency so in this case we will do it by the book! You could run it at 3.3V and see what happens with the stability and the CH340 USB to serial converter… Usually it works very well! It would make for a little simpler construction. But this time I am going for proper! 🙂

Pin Connection

See the above picture on how to connect the pins together through the level converter. The yellow markings (left side of the converter ) goes to the yellow markings on the display contact and the blue ones (right side) goes to the Arduino. Note that the display MISO pin goes directly to Arduino pin D12 – no need for the level converter! Also note that the level converter is having its low voltage side towards the display contact! Click the picture to see a larger one!

When connecting the pins according to above be aware that the +3.3V will have to come from a separate 3.3V voltage regulator! I mentioned earlier the voltage was too high at the 3.3V pin on the Arduino – that was measured unloaded. When testing it with a load the voltage was just 3.1V which instead is too low! So a separate voltage regulator is still needed! The FT232 specifies that it will supply 100mA at 3.3V – but I guess the replacement CH340 will not! 😦

Please go through and check everything an extra time! Then after making all the connections described above it is just to keep your fingers crossed and hope that you have connected everything correctly! Connect the USB cable between computer and the mainboard! First of all you should at least see the background LED of the display com on! After this it is time to try the display! Bear in mind that different graphics libs expect different pin connections!

Display chip and test

If you have not found out earlier it is now time to find out what display chip you have! Search the internet for info to help identify it! I searched for the model name “TJCTM24024-SPI” written on the back of mine and found out that my 2.4″ TFT Display uses a display controller called ILI9341. Therefore it will need a graphics lib that supports that display chip. Somutoy has a few libraries for different display chips here – I have used them before with very good and fast results on a smaller display – but I do not know the current status as it seems there are a few issues reported back in 2016 that still are not fixed… Adafruit also have good libraries here – well they have a lot of good libraries for a lot of different things! I will try both and see what advantages/disadvantages they have!

The first test of the display went almost well! I just tried out the Somutoy library and most calls worked alright – BUT testing the example “Graphictest” it locks up at fillrect()-call! 😦 All else works nice! This shows that the display is correctly connected – which was what I wanted to test! The lock up seems to be some kind of timing problem with the fillrect()-call when a certain size of rectangle is to be filled!

Running the same “Graphicstest” with the Adafruit library it works as it should – albeit a bit slower and faster. Just out of curiosity I decided to run the libs against each other to get a better grasp of the differences! Look at the graph above for details! What is quite apperant is that the Sumotoy lib is substantially faster at lines and triangle outlines. When it comes to the rest the differences are smaller with 4 being faster with Ardafruit and 4 faster with Sumotoy! I have understood that the Sumotoy lib will work even faster with a faster processor/faster communication – but on a ATmega328 at 16MHz the advantages are not stellar! It is a pity to miss those superfast lines with the Sumotoy lib but not having a fully working lib is not good either … But here we could still pick the Sumotoy lib if we knew we would not be using filled rectangles and that lines were often used …
Note: The tests were run at 3.1V. They excluded filled rectangles. I will redo the tests at 3.3V when I have installed the extra 3.3V regulator!

Internal Power Supply

NOW I have installed the LM1117 3.3V regulator! Things happen so fast sometimes when you write! 😉 Well, the “Graphicstest” shows that there were no notable speed differences at 3.26V – as was the new voltage under load. That voltage is just a little over 1% low – and that is also the precision of my multimeter! 😉 Nothing to worry about here! Compared to the original supply (fed from the CH340 3.1V) it showed no real differences in speed! One might simplify matters and skip the extra voltage regulator …? That is always the problem when dealing with reality! Sometimes the theory just does not matter that much … Well, I have already put the LM1117 voltage regulator in place so I will go with that! It is fed from the 5V line and can supply more than enough current for the display so there is no real reason to bring over 3.3V via the multi-point contact and that frees one contact …

Next time it is connecting up the MCP4725 DAC:s and testing them!

See you soon!
/Sfenn

 

Ar2uino Digital PSU – 3

For this design I have gone for using the handy small “functional boards” or “breakout boards” that you can buy on ebay and other places. It is usually an IC with a specific function, like above, a DAC and its required support components mounted on a small PCB. It really simplifies the practical construction – especially with small size SMD components! Very handy and usually not very expensive!

The Components

Above you can see most of the components before assembly. Mainly the Arduino Nano and the TFT 2.4″ Display but also a number of sockets and mounting details. Added to that are a few ICs, both on their own and mounted, by me, on breakout boards. The complete list follows:

  • Arduino Nano 5V
  • TFT Display 2.4″
  • 12 bit DAC MCP4725 * 2
  • Current Sensor Amp LT6105
  • Op-amp CA3140
  • Op-amp LM358
  • Level converter 4 channel
  • Power Darlington Transistor
  • Voltage Regulator L7805 – 5V
  • Voltage Regulator L1117 – 3.3V
  • Voltage Regulator LM317 – Variable but set to 3.3V
  • Capacitors: 250uF, 10uF, 0.1uF*2, 56pF
  • Resistors: 180k, 22k, 2k7, 2k2*2, 1k, 330*2, 0.1 ohm. (All 0.25W except 0.1 5W)
  • Trimmers: 100k, 5k, 2k5
  • Rotation Encoder w switch
  • USB Micro socket (on a breakout board)
  • Power supply socket 5.5/2.1mm (1 Needed. More is optional!)
  • Banana socket *2 (Optional! See Power Supply Sockets above!)
  • Headphone Stereo Sockets * 5
  • Pin headers, perf board, wires…

NOTE! The above are the components that I started out with. As this project continues these might change! When the project is finished I will update the above and remove this note!

The general idea is to minimize loose wires by fitting most components on one board – the mainboard! That will contain the Arduino Nano, display and the major part of all electronics! The other things will be mounted onto the box and on the front panel and all connections to the mainboard will go through one or two multipole contacts. It is quite amazing how quickly the connections adds up! I am up to 24 pins at the moment! 🙂

Fitting the Components

As this will be a one-off I will be soldering the components onto perf boards as can be seen above. I will use thin wire wrapping wire to make all the connections. Only for the wires carrying any real power will I use heavier wires.

Thanks to the “functional boards” fitting most of the components is very quick! It will still take some time to solder all the connections though! Fitting the components to the perf board is rather free – do it as you see fit. I have kept it rather spacious – using most of the perf board! It can easily be made more dense! Solder just one or two pins for each small board at the moment – just to hold the parts in place! I have tried to minimize wire length and to keep analog and digital separate as well as I could! Also I needed to factor in that the TFT Display with its SD-Card reader must fit on top of the components! An Eagle schematic will be added at a later instalment – when I know the design works!

In this picture you can see the mainboard with all the digital circuits soldered to it. A 5-3.3 voltage level converter (top left), two MCP4725 DACs and the Arduino Nano. Connect the Mini USB connector on the Arduino Nano to a pin strip (5 pins) – on the rear side of the board. Just preserve the same order of the connections as in the USB contact – and it will be good! From top:. You can just about see the soldered pins to the left of the Mini USB connector on the Arduino. To the very left is a big contact for the TFT Display and to right of all components is a small contact for the SD-Card reader. On the lower left is a big pin strip to connect to all the parts fixed to the box. To the very right is a (so far) empty space reserved for the analoge circuits! On top of the above digital components the TFT Display will be fitted. Note that I have trimmed down the perf board slightly! That is just because I want the box to be a little slimmer.

Instead of using a mini USB connector as I did you can also solder thin wires directly to the PCB tracks to the right of the connector. I deemed this to be to tricky – at least for me – therefore I used the USB connector! You can see it here. Note that it is turned belly up so the connections are in reverse! I might add a small dot of hot glue to make sure it stays connected – but it is already a pretty firm fit!

The reason for using a separate 5 pin strip for the USB is so that the Arduino and the display can then be programmed and tested with only the USB connected. No need for the whole analoge power section to be powered up!There has to be a way of disconnecting the 5V supply that is through the USB later when you will power it from the “real” power supply! I have added two pins with a jumper to do that but you might as easily just cut the +5V (red) wire from the contact when you are ready with testing and development! With a jumper added you can easily reconnect it … if ever needed – or even add a switch to the back of the box …! WARNING! Getting 5V from both the USB and the power supply at the same time is NOT good! You might harm the Arduino or your computer!

Next is to make a pin strip to micro USB connector. That means that the Arduino can be tested to function with the USB cable. As you probably noted I took the opportunity to convert from the Mini USB on the Arduino to a more modern Micro USB that will be fitted to the PSU box. (Note that the wire colours are NOT the standard ones! But just keep track of which way to plug in the GND and the rest will sort themselves out! In my case Brown=Black=GND)

WARNING! If you turn the pin connector the wrong way you might FRY the Arduino!

Connecting the USB cable to my computer is the first test and showed the Arduino D13 LED could be blinked! That proved that communication and power supply through the USB connector worked perfectly. Yeah! 😉

I wanted to use the 3.3V output pin on the Arduino to drive the TFT Display and its background LEDs. BUT measuring this voltage showed that it was 3.6V and not 3.3V as stated! As this can have bad long term effects on the display I will add a separate 3.3V Voltage Regulator (LM1117) to get a more correct voltage when powering the Arduino from the USB! Might it be that the cheaper CH340, that is replacing the standard FTD FT232R that is originally is fitted on the Arduino Nano, does not contain a proper voltage regulator to convert 5V to 3.3V? I will admit that the not-so-easy-to-read CH340 data sheet is a little bit unclear on this … That is nothing major but a slightly irritating minor complication that I guess stems from buying all these cheap components!

Next it is time for connecting up the 2.4″ TFT Display to the sockets.  😉

See you soon again!
/Sfenn

 

Arduino Battery Tester v3 – 1

By far the most read of my articles are the ones about battery capacity testers! No wonder when you are thinking about the outrageous larger than life battery capacities that some manufacturers write on their batteries! It is like the batteries have arrived from outer space! I have already built two testers! 🙂 1. A simplistic one that just mimicked taking pictures with a camera. 2. A second, much more general tester, with changeable load resistors. Both have been read a lot and I hope built also! They are very simple to build and contains just an handful of components! Very easily to built on a piece of perf board. You find them in the “Categories” links on the side!

What has been appreciated with the second one is that it has fully automatic functions for identifying the battery type and will set the cut off voltage according to battery type. Also the fact that it could present a proper discharge curve. Well it gave all the values to use with Excel or other spreadsheet programs to actually create the curves!If you are measuring similar batteries most of the time then you have got exactly what you need already – you do not really need more than that! Because when you have decided on the load and mounted the load resistor you do not have to do anything more! Just test! 🙂

My thinking for this new Arduino Battery Tester is that I will use the MOSFET Power Transistor as a variable resistor instead of switching on and off the load resistor! The advantage will be that there is no need to change the load resistor ever again! The circuit will be very simple and very similar to the last one and the components not many more – but they will have to be swapped around a bit and we will use more inputs on the Arduino! The biggest difference is that while previously the load resistor got hot – now it is the transistor that will be HOT and will have to be cooled with a heat sink! Naturally the software will also have to change a bit with a control loop for the transistor!

The heatsink and the transistor will have to be chosen/adapted to how many ampere load you want to test at most! In my own construction I have aimed for 3A as a maximum. Then I can test power banks easily! They often declare that they will supply 1A up to 2.4A at 5V for charging of a smartphone. Adding a bit of margin: 5V at 3A gives (5*3=) 15W heat that will have to be cooled off. The 0.33 ohm sense resistor we will use will have to handle about 3W of those 15W – so that gets pretty hot as well! I might even add a fan to be able to make the heat sink more compact!

Then I realized that there were at least two really different ways of doing this! The minimum fuss way and the bigger changer way! After some consideration I realized that I would have more challenges and learn much more by going the latter way! 😉

So … I will swap the trusty ATmega328 for a ESP8266 and have the battery tester both controlled and also presenting info through Wi-Fi! You will be able to use it from your iPhone, iPad or even your PC. (And yes, you can use all kinds of other ‘smartphones’ as well!) This means that there will be a completely new software as well – based on a webpage layout!

The hardware will not look much – just a box with a heatsink and the battery under test! BUT it will look very snazzy on the screen! Moreover the collected data can be very easily copied to a computer or similar through the webpage! It will be powered by a standard 5V USB charger!

Anyone interested? Should I write up a few posts on this?
Let me know through the comments on the lower right! 🙂

UPDATE: So far only ONE comment wanting this … so I am going to focus on getting the Digital Power Supply ready for a little while …!

Hope to hear from you!
/Sfenn

 

 

Home Automation System – Radio

Well, I will just jump right in and tell a little of how I see my upcoming Ar2uino DIY Home Automation System (HAS) project! Seeing how important the Radio Communication is in this type of system I have decided to start with the radio part! Going with my original idea that a module in a DIY Home Automation System – a small processor, a radio and a power source – has to be inexpensive and easy to build and be very flexible!

Radio Modules

I will call the above mentioned module for a “Node“! Also we will have a central Node with more responsibility than the others! I will call it the “Master Node” or just Master for short!

I have scanned the market for inexpensive and capable radio modules and have found several alternatives but no one that is as inexpensive as the Nordic nRF24L01+ (seen in the big picture above) and at the same time it has decent, if not particularly stellar, performance.

The Nordic nRF24L01+ is what is called a “Transceiver” it holds both a transmitter and a receiver! That is very handy – surely even necessary – in a HAS! You want to be able to get confirmations from the Nodes that they have performed their requested “action”. Also they can easily gather information and send it on. It can even off-load some communication related chores from the processor but requires then that we use its features. There exist many different versions of this radio or RF module and even a few clones that promise even better reach. I have a number of these different RF modules that I plan to test before going on with the HAS.

Radio communication is a little bit of magic I think! Understanding why it works and why it does not work can baffle anyone! The nRF24L01+ is using roughly the same 2.4GHz frequencies as Wi-Fi and microwave ovens(!) so it will have to compete to be heard over the “RF noise” leaking out when you micro popcorn and then again compete with the Wi-Fi when you watch a movie on your iPad! 😉 Also there is the problem with walls (well, any obstacle) and humans! Walls are at least not moving around but they still dampen or completely sucks up the radio signal as it passes through – or not. Humans are like moving walls to the radio signals blocking a signal that just a few seconds earlier passed without any problem!

An alternative could have been Bluetooth Low Energy (BLE) that can work for several months to several years on a 1000 mA battery! That would be more like what is needed for a DIY Home Automation System Node. But even if that is impressive the price is way too high at the moment – I think! It could come down quickly! Just look at these Bluetooth baggage tags that work 6 months on a CR2032 battery – if they were user programmable … wow! I tore one apart(See picture!) just to see how they were built and with what components … IF they can be used as Nodes – will be another project!
Put into low power sleep they could maybe last years on that battery! Well, it all boils down to the
price and the power consumption – and programmability! In a few years time when demand has risen for these BLE products someone will probably design and build small BLE based Nodes in the millions and sell them for a few Euros!?

So communicating between the Nodes is one of the greater challenges that has to be handled in some way. No (or at least very few) messages sent between the Nodes can be allowed to be “lost”! One way we can do this is by acknowledging (ACK-ing) each received message and if no ACK* is received by the sender then it will resend its message again … and again … and again … as many times as we se fit! It might even wait some random time between retries to avoid repeated “collisions”. The disturbance can actually be another Node trying to send its message as well! This must be handled on top of all walls and all humans! 😉 The solution to these “disturbances” is mostly to resend the message so the ACK is a very important concept! But to complicate matters – an ACK can also be lost even if the original message actually got through!
* Most of you probably already know that an ACK is just a short message sent from the receiver of the message to the sender that the message was received ok!

DIY Nodes

So what do I think is important in a DIY Home Automation System Node? Well, I have already said that I think that it should be inexpensive and easy to build. That also goes hand in hand with that I think that it will NOT have to be very powerful or have lots and lots of inputs and outputs! Nodes should instead be VERY power efficient! With that I mean that they should preferably be able to function several years on a small battery!

Naturally some Nodes (like the Master) will have to be powered by mains power but the fewer of the Nodes that has to rely on mains power the better! Remember that each mains powered Node requires a mains power adapter and do you really want to sprinkle the house with dozens of Node power supplies? You will soon have no sockets left for lamps and TV! 😉 It is, at least at the moment, not possible to entirely avoid mains powered Nodes – there will be enough of them – but some (outdoor) Nodes can probably also be solar driven – especially sensors that can “sleep” until they wake up either by timer or some other means and send in the observation!

Probably Nodes will be developed by companies that have much more resources than we as amateur makers have to develop an amazingly small and power efficient Node module that will amaze us with its abilities in a few years and at a price that will seem ridiculously low! But at the moment we will have to pick the best of what exists – and to balance requirements against cost and power! Having looked at where I would like to have these Nodes I would say that in a lot of cases small size is not very much required! It would be no disadvantage but not needed! Power use and radio power are more important!

Processors

I have more or less decided on Arduino Pro Mini with a ATmega328 as the processor for the Nodes! There exists several very impressive micro controllers and even small computers today – that would serve extremely well for any Home Automation System! We have the ESP8266 and the ESP32 with lots of processing power and even built-in Wi-Fi! The Raspberry Pi is an amazingly small but still a complete little computer! With these alternative processors we get radio included making it a little difficult to separate processor and radio.

All of these different alternatives could easily handle ANY task that we give them. BUT would it be reasonable to have a Raspberry Pie stand by each window and send a message if the window was opened or to send off the current temperature in the basement once every 15 minutes? No, of course not! That would probably be silly!

To my way of thinking even an ESP8266 would be way overkill for these simple tasks! Pricewise the ESP8266 is more than OK nowadays but it consumes too much energy! Very good for the Master though! Also the way of communicating, Wi-Fi, is too complex and require too much energy for the ordinary (battery operated) Nodes!

Therefore, an inexpensive, programmable Node that can be in low power sleep mode most of the time using only a few µA or even sub µA and that has just some free inputs and outputs – that is my ideal Node! Funny really that weakness will be its biggest strength! 😉

I plan to build a handful of these Nodes so that I can test the communication properly between them. In spite of my recently finished amazing 😉 Ar2uino Reflow Oven these Nodes will be hand soldered! Built of the mentioned small radio and processor modules. I expect many of the Nodes to be bult by the ready-made modules – as it is by far the cheapest way to build them. The separate components cost more and then I also have to add the cost of a PCB. Still I do plan to design and build a Node myself just because it is sooo COOL 😉 – but that will have to wait a little…!

As I seem to recall having said before: The software and the hardware must work together to overcome the challenges in any system – in this case the Home Automation System! A weakness in hardware might be helped by a capability in software – and vice versa! A Node would be nothing without its software – that is the “brains” of the Node!

The “snaky” golden line on the right in the picture is the antenna. It is just a few cm long and is responsible both for receiving and transmitting the radio signals. How this small antenna is designed and implemented matters a lot to how good reception (and transmission) a RF module has. Metal and water, among other things, block the signals very well. This boils down to the fact that how we put the Node together (radio and processor) will affect the quality and the reach of the radio signal. Here I have put the parts back to back – giving a very compact node. Testing will show if it is good … or not?

This I will test by putting my first – hand built – Nodes together each a little different from the other. This is so that I can test and see if a certain construction gives a better or worse range!

The first test I will make is to try and see if any type of nRF24L01+ (or compatibles) is better than the rest? Because it is easiest to measure I will use a simple (hopefully correct!) assumption: If it works best in a free line of sight situation – then it will best used in a house as well! We are here talking of different hardware modules but all using the same RF-protocol!

Plan

As I said before this is a “journey of learning” and naturally also of making – but learning comes first! 😉 I have done some very small basic testing of the nRF24L01+ modules before and I thought that it was worth a further (proper!) testing! I thought they looked very promising then – but who knows – I might have to change RF-modules if they turn out to be a disappointment!

After quickly reading through of the data sheet of the RFM69HW RF module it seems like a decent alternative candidate! It is missing some of the communication features of the nRF24L01+ and is a little short on the address side with just 1 byte. So it will load the processor a little more and require a bit more programming in those areas … but it uses the better penetrating 868MHz that also is not so busy and has hardware encryption and higher output power so the reach should be better … but then naturally using a little more power!

My general preliminary project plan for the DIY Ar2uino Home Automation System is this:

  • Build a handful of Nodes
  • Test the range of my different RF modules outdoors
  • Test the Nodes in view of power consumption
  • See if I can learn something of the above for the Node construction
  • Work on the network communication protocol
  • Develop secure (encrypted/digitally signed) messages
  • Design the “Node OS” or common software base for each Node
  • Design and develop the Master
    • Develop the Webserver
    • Web interface (iPhone, iPad and PC) using HTML5
    • Logger development
    • Internal communication (I2C)
    • Many more different Master parts…
  • General testing
  • Nodes, Nodes and Nodes

See you soon again!
/Sfenn

Ar2uino Digital PSU – 2

While waiting for the components to arrive I have started to do a little testing on various aspects of the PSU design. There are naturally many things to test out and to show proof of concept for. Some of those things can actually be tested right now without any of the components that I have sent for!

In my last post I showed the general block diagram over the PSU Design. As you might have noticed I have decided to go for a “modern” design using specialized IC:s and a microcontroller. That microcontroller will give me the options to “easily” add extra features not normally possible when having a fully analog solution – without adding much more than a little programming! 🙂 One thing that I want to be able to have is both analog normal current limiting so I can set a max current and the PSU will supply that – in a constant current mode! But I also want to be able to – both for limiting the heat generated with using lower voltages and higher currents and to protect the components under use – have current foldback! I plan to use the microcontroller to accomplish that – digitally!

The microcontroller will constantly be monitoring both the voltage and the current to display them on the screen. To do that very high speed is not required! A few updates per second will suffice handsomely! To have current foldback the reaction must be MUCH faster! So my first bit of “research” will be into the Analog to Digital Converter (ADC) in the ATmega328. How fast will it work and how precise? The ADC will be an important part in getting information to display! But will it be up to par when it comes to actually do something?

Microcontroller ADC

The ATmega328 ADC can be used in two ways: Either you call the ADC for an analog measurement and wait for the result. You can do nothing else while waiting! 😦 That is using the standard Arduino “analogRead()” function. Very handy for one-off reads or when you have a certain schedule or process to follow. OR you can use a “free-running” or “looping” ADC working with interrupts. That way the ATmega328 will handle the ADC in a loop on its own and you can “read” the last measured analog value from an ordinary variable whenever you want to – and NO waiting!. Very handy! So how fast will this be? How often is that variable updated? And how repeatable?

I set out to write a small program to test this. And while doing this wrote a few small library functions to simplify the use of this – for use later on in the “firmware” for the Ar2uino Digital PSU. I connected the Arduino to a stable voltage source and let the ADC run free! 😉 Ideally all measurements would return the same value. In real life two or maybe three values would be perfect! It was very clear that the little ATmega is not bad at all! It normally (with the standard settings) and the standard analogRead()-call will do a little over 9000 Analog to Digital Conversions per second and it will return a 10 bit ADC value! What is controlling how fast the ADC will work is a prescaler that can be set to different values ranging from 128 (default) down to 2. Changing this prescaler will give a different number of ADC:s per second. As can be seen in the last line in the table a little further down in this post – you can see that we get from 9 600 up to almost 154 000 readings/second. Above that the resolution will go down and the full 10 bits will not be available/correct. BUT you CAN go higher – at a cost of lost bits! That was not so interesting for this solution. I wanted full 10 bit resolution and repetable readings!

Translated into response times these are from 104 uS down to 6.5 uS. So – at least theoretically – the ATmega could fold back the current digitally in just 6-7 uS! Wow! To me that sounds good enough – especially when considering that analog current limiting will most probably(?) have cut in before that! So it might be kind of a two step process: First the normal current limiting kicks in and then a few microseconds later the digital current foldback kicks in and cuts current (and voltage) down to close zero! Might not even need that kind of reaction time? Running the ADC a little slower at speed 4 (77 ksamples/sec) will give a reaction time of 13 uS. I will have to research how fast I need! 😉 How fast is a good PSU? How will we end the fold back? Disconnect, time or button? Googling did not come up with any good numbers – so more “proper” searching is necessary!

In my design the digitally controlled current foldback would work like this: The ADC runs free at 154ksamples/sec. It generates an interrupt each time – every 6-7 uS! Within this interrupt we check the current against a set foldback limit. If the current is  exceeded  the ATmega activates the fold back transistor and thereby folds back the voltage (and current). I do not – yet – know the time it would take to actually fold back the current for the transistor to react and any capacitors to empty – but will measure that later on! Clearly the potential is there, I think, for a simple and elegant solution – if I may say so! 😉 Feasible YES! But am I sure? No! How much of the ATmega total processing power will these interrupts every 6-7 uS use up? Will I have to “slow the ADC down” to leave some capacity for all the other things I intend to use the ATmega? Naturally I will have two “processes” or “tasks” going on at the same time: The free-running ADC for the current foldback AND the other tasks of reading the rotational decoder and the voltage and updating the display and …

Next question is naturally if the ADC is precise/steady enough at these speeds? Look att the big diagram at the top. It can easily be seen that IT IS! The lowest free running ADC is very similar to the standard readAnalog() call – in that the values returned are into two nearby “bins”, B614 and B615. That is GOOD and stable! I set the program to stop when 5000 measurements had been added to a bin. Speeding up the ADC it focuses mainly on B615 with very few values in the nearby bins! They are so few that they are hard to see! But they can be seen in the table! This is also very GOOD and very stable!

What about the two highest speeds – 6 and 7? Well they seem to loose precision – even if they give a very steady reading of a steady voltage! It returns the “same” value all the time! Where the lower speeds gives the same value as the volt meter these measured with the two higher speeds returned values that are sometimes a little low and at other times a little high! We are talking within +- 10 mV. It is quite clear that the ADC works at these high speeds but is not so precise – it looses a few bits! So unless it shows that I will need these higher speeds I will stay off them! I can also vary ADC speed according to what I need for the moment! So if I do not have digital current foldback active I can run the ADC at a lower speed.

Should the ADC solution not be fast enough – I do NOT want to burn components OR ruin the PSU – another solution is using the built-in ATmega analog comparator! That works off the same voltages as the analog current limiting and is very fast (around 500 nS) and can generate an interrupt where you activate the fold back transistor in the usual manner. The drawback is that it consumes two extra pins … and I have already ideas for ALL pins of the ATmega! 😉

Summary is that I think that the ATmega ADC will be good enough for a digital current foldback! At least for now! Until a good PSU has been researched and transistor reaction times have been measured and I can get the total picture! 😉

See you soon again!
/Sfenn