Tuesday, 3 May 2022

Trying To Repair The Batteries On My Drone

 A couple of years back I found a drone, complete with all its accessories and bag etc in the trash. Someone had thrown it away because one of the propellers didn't work, and the reason it didn't work is because one of the wires connecting it to its motherboard had come loose. After 30 seconds with a soldering iron and a meter, it was back up and running again, and I had a complete drone with kit for free.

Since then, it has taken a few more knocks - one time it got stuck in a tree after an unexpected gust of wind and came crashing to Earth whilst I went to get a long pokey stick to help it down. But overall I have been able to keep it in good working order, despite some cosmetic damage.

Sadly though, after some storage over the winter, I have discovered that the batteries for both the drone and its controller now seem to be unable to take a charge. I did think that this could happen for the controller, as the battery cannot be easily removed from it - but the drone battery pack is removable for recharging and storage. It was disconnected from the drone when it went into the cupboard in December, so I am a little unsure as to why it is behaving this way...

I am going to start with what I think is the easy win right now, the controller.

Partially disassembled controller

The first thing we need to do is extract the battery from within the controller itself. It sits within a cage that also has the antenna hot glued to it. When I first rescued this drone, the controller had these big, flat, folding antennas on each corner. Once I got into the controller itself, I discovered that they were ornamental - they were just pieces of plastic, so I took them off and binned them.

With the battery out, I need to measure its current voltage. As the label suggests, this is a 3.7 volt 350 mAh battery, so we want to see something near this value when it is working correctly. As I am typing this, I haven't measured anything, so at the present time I think it is going to be pretty low...

The controllers internal batter


After measuring the battery on the meter, I was very surprised to discover see 4.26 volts come up on the display. So much so that I measured it again on a different meter - and got the same measurement again. This is very strange, one of the features on the controller is a strip of LED's that provide a battery status. When connected to the power, they also act as a charge indicator. Before opening the controller, the LED's were flashing in a specific pattern, but with only two of them lit. As one of them was orange, I assumed that this was the charge/on light.

This means that it might not be an issue with the battery charging in the controller, it could indicate a larger problem with the controller itself. I dont know if these types of battery can be "over-charged", or if the existing battery is damaged, so its probably a good idea for me to go ahead and replace it any way. And if I am going to replace it, why dont I increase the battery capacity at the same time? On the original battery I got about 20 minutes of flight time. The drone itself can last a little longer, but having a higher capacity battery on the controller would be incredibly useful.

Going through my current battery collection, I discovered a 3.7 volt 300mAh which shares an almost identical physical configuration to the original battery. However it is a lower capacity battery at 300 mAh, which would mean even less use time on the controller itself. 

But, I have quite a few of these batteries, so why not use more than one to increase the capacity from 300 mAh to 600 mAh?

In pretty much all cheap electrical consumer products, we see multiple batteries being used. Typically these are an even numbered combination of AAA, AA or D cell batteries. These batteries normally provide something between 1.2 and 1.5 volts, however the devices they power often require voltages higher than this or capacity that exceeds that of one single cell.

This is why we have to put batteries in these devices in specific combinations, and each device will require either one of two configurations, those being parallel or series. Connecting batteries in series increases the available voltage, so connecting six AA cells in series would give you 9 volts, depending on the cells. Connecting the same number and type of batteries in parallel would give you a voltage between 1.2 - 1.5, depending on the cells, but the capacity will have increased six fold.

To connect two or more cells in parallel, you simply connect the positives to the positives and the negatives to the negatives. With this done, you have increased the capacity by creating a battery pack. To connect the batteries in series, you connect negative to positive etc. Once done, you will have increased the voltage by again creating a battery pack. This is the reason why we place batteries in devices pointing in a specific direction. 

For my purposes though, I will be connecting two of my 300 mAh batteries in parallel for the reasons described above. The following image best describes what I need to do in order to achieve this:

Connecting batteries in parallel with strip board

Unfortunately, my two replacement batteries cannot be squeezed into the existing battery cage - and I dont want to make any physical changes to it as it acts as the antenna holder as well. However, there does seem to be plenty of space in the controller for these to be held in place with some command strips. However, I can use the holder to take care of a piece of stripboard to handle the connection to the controllers mainboard.

I actually find that drawing things out on a piece of strip/perf board helps me with routing tracks and any jumper wires I might need to put in. I also dry fit the components to help me realise the orientation and correct placement for them. Using Fritzing, the application I used to generate the previous image, helps a lot. But when you cannot find the same part you are using for real in its menus, getting your actual board realised needs some planning. I used some copper tape to indicate where I need to join tracks, and have also marked where tracks need to be cut. The copper tape isnt great as a conductor on its own, but you can use it for a continuity test. There would also be a jumper on the reverse to join the two upper tracks, however I have omitted this. 

The completed battery board ready to go into the controller

With the board finished and all of the relevant connectors soldered into place, I was able to fit this into the battery cage in the controller. The batteries were fitted into the shell of the controller and I rebuilt it enough for it to be able to go on charge. I was pleasantly surprised to see that once it was connected up to a USB C cable, the controller began to charge the batteries. So I went ahead and put the whole thing back together.

the battery board and batteries installed in the controller

After about an hour, the charge light went off and I decided to turn the controller on to see how we were doing. 

Sadly, even after replacing the batteries, the controller refused to work correctly. It was showing the same flashing LED's - which I think must be an error code - as it did with the previous battery.

So thats one dead controller...

Next up is the main battery for the drone itself. This charges via a USB adapter that was in the case when I found it. This is pretty essential, as without it I would have been pretty much unable to charge the main battery. Whilst charging, the LED's on the battery are supposed to light up and indicate the charge level. However now, they are completely dead.

The battery is marked as 11.1 volts with a capacity of 1600mAh. It also states that it can deliver 17.76 Wh of power. These are pretty capacious batteries for two reasons - they supply power both to the avionics and to the propellers. The propellers will use the majority of the available power for achieving flight.

I hooked the charger up to my USB meter, this is a really useful tool for looking at what takes place over a USB connection. It can be used to measure the voltage, current and power being used by a device that charges over USB as well as monitor the same over the D+ and D- lines. However I noticed that whilst the batter was connected to the charger, there was no power draw. I would expect to see something around 1.5 amps if this battery was charging correctly. This is because the charge cable states it has an output of 11.4 volts and 1.5 amps.

USB meter used to monitor power draw



The only other thing I could do at this point is to check the internals of the battery itself. Within, I found that there were three 11.1v cells connected together, given the parameters of the battery that I already knew I assumed that they were connected in parallel, in the same way I approached the controller. But of course, this batter has circuitry that is much more complex.

I think its probably a good point in time to state that working on a battery like this is not a trivial matter. The risk of shock is high, and whilst not that dangerous to you, it could be painful. However, the risk of rapid battery failure in the form of smoke, flames and explosion - and I am not kidding here - is pretty high when you are dealing with a something like a battery pack that will no longer charge. Its always a good idea to have a flame proof container like a biscuit tin, or oven pan to hand so that you can quickly dump a failing battery. One time I opened a battery pack that had taken a knock ended up with one of the cells rapidly expanding and becoming scorching hot with seconds.

The exposed battery pack



After getting the pack out, I checked for any obvious damage to the cells themselves. If you see a LiPo with damage to the edges then be wary, its often ones that have been bashed on the edged or corners that like to go nuclear. Plugging it back into the charger allowed me to probe around some of the connections.

This helped very little other than to indicate only one of the cells appeared to have any charge, and this was at 12 volts. There was no sniff of power anywhere else on the board at all, none to the LED's or the single button provided.

The battery packs circuitry



So sadly, it looks like the charging capability of the battery itself has ceased to work. It is odd that both batteries would go at the same time, especially after being stored in the same way. But I needed to remember that this is a piece of equipment I dug out of the trash and got working again, I dont really know if the initial problems were caused by something else, like a formidable crash.

Where does this leave me? Well, with no drone any more it seems. Unfortunately, I haven't been able to repair any of the damage to my drone at all. Its pretty hard, if not impossible, to find replacement parts as well. This was a mass consumer device made with some specific parts, I can take some bits and pieces off the shelf as replacements, the propellers and motors etc, but the charging is handled by the battery - the cost of one of those right now is almost as much as buying a new drone. So I wont be doing that. Also, the mainboard for the drone is not able to be customised, I cant replace the firmware or anything else on the board at all. Right now, its dead.


Did I learn anything? Well, initially this want an exercise to learn anything new in particular - if anything I have come away from this with more questions about batteries as it turns out that I know less about them than I thought. But one thing I was able to improve on here was my skills in diagnosing potential problems. A list of checks was written down as well as me working back from where the power came in with a meter to see where things went wrong first.

Which is great etc, but now I just dont have a drone 😞



Saturday, 5 September 2020

Serial Communications with Arduino Part 2 - Software Serial Ports

 Last recently, I put up a short post on how we can use Arduino to read data from a device. Cunningly, I made the process so simple (mainly for myself) that I neglected to actually use an Arduino.

So, in this post I will remedy that by providing an example on how to read data from a device using serial communication at the start, then move on to writing to the serial port.

In the last post, I gave an example of how you can connect a USB to TTL adapter to a device and read its data. This time round, we are going to use the UNO R3 to act as our USB to serial adapter. To do this, we are going to be using the following

  • 1x    breadboard
  • 1x    Arduino UNO R3 
  • 1x Neo-6M/GY-GPS6MV2 GPS Module
  • 1x CH340 USB to TTL adapter
  • Jumper wires

The proposition is quite simple; we want to send the output of the GPS module to the board over a serial port. Unfortunately, I have not found a way to simply connect it to the TX/RX pins on the board itself and have it output data. So, to accomplish this we need to create a second serial port to handle the incoming stream of information from the GPS module itself and we need to create that port in software.

To do this, we are going to have to use the Software Serial Library.:

1:  #include "SoftwareSerial.h"  
2:  SoftwareSerial ss(8, 9);  
The first line references the library we need to use in this program. If you get an error when compiling this code, you might want to check that you have this library installed from within the Library Manager.

The second line is simply us creating a new software serial port called "ss", the numbers following represent the RX and TX pins on the board.

Next, we have to set up our ports, this should be familiar to anyone who has been using the Serial Monitor from within the Arduino IDE: 
1:  void setup() {  
2:   // put your setup code here, to run once:  
3:   Serial.begin(9600);  
4:   ss.begin(9600);  
5:  }  

Here we can see that on line 3 the hardware serial port is started with a baud rate of 9600 - this is the speed at which the port is reading/writing at. Line 4 is almost exactly the same, however this is the software serial port that is being started this time, note that we are also starting it at the same baud rate.

From reading up on using this library, it seemed that 9600 was the highest baud rate to go for and still have a stable connection. The GPS module can work up to 115200 baud, however when I configured the serial ports to use this speed, nothing happened.

Next up, we have the main executing of the code itself. We read the data leaving the GPS module on its TX port on to the boards hardware RX port and vice versa: 
1:  void loop() {  
2:   // put your main code here, to run repeatedly:  
3:   if (ss.available())  
4:    Serial.write(ss.read());  
5:   if (Serial.available())  
6:    ss.write(Serial.read());  
7:  }  

Line 3 checks to see if the software serial port is available, if it is then the hardware serial port then writes whatever the software serial port is reading on line 4.

Line 5 does the opposite, if the hardware serial port is available the software serial port writes whatever the hardware serial port is reading - which happens to always be whatever the software serial port is reading due to the structure that we have created.

Think of the above as an exchange - the hardware serial port is empty until it reads the incoming message from the software serial port. Once it has that, then both ports will have the same message.

Make sure you have your serial monitor running when you upload the code, you should see something like this:


The full listing for the code will be at the bottom of this post.

At the start of this article I mentioned that I used a CH340 USB to TTL adapter for debugging. This is because I had a fairly hard time getting the software serial port actually doing what I wanted it to do, quite a few of the articles I had read on the subject provided examples that simply did not work so I began to think my GPS module had become damaged.

So, to verify that the GPS module was working whilst the board was running the code, I connected it in series with the wires going from the GPS module to the board.

This let me run putty to make sure that I was getting something from the GPS module itself and make sure there was an incoming message for the board to do something with. It was actually quite helpful to do this while figuring out my problem. 

The setup, minus the USB to TTL adapter, looks like this:


If you are trying this out for yourself, then hopefully you are seeing a nice barrage of NMEA sentences scrolling across your serial monitor.

However, if you are seeing nothing, then try swapping your RX/TX pins on the board itself. You might have gotten them mixed up - I certainly did a couple of times.

SoftwareSerial is not the only library available that can do the same thing. Another, very popular library you can install is AltSoftSerial. Syntactically, it is almost identical to SoftwareSerial and supports a wide arrange of MCU's and development boards. You can also use a mixture of different libraries to give yourself multiple serial ports to work with, should you need to, for example if you had a number of devices that provided data in the same way as the GPS module you will need to have more than one serial port configured to a set of pins. That way you will have an uninterrupted flow of data from each device on its own serial port.

So what does all of this mean? Well essentially it is just a description of how you can easily set up a couple of serial ports to share data. But in this specific context, where could we take the build next? We are using a GPS module and we can see the NMEA sentences that it is receiving. We also know that each sentence begins with a $, so we could easily read the sentences into an array or object in order to process them further.

From looking at the output, we can see that there are six distinct types of sentence being received, or at least the module is trying to populate the contents of six sentences with data from the GPS constellation, with that knowledge we might be able to do something useful with that data...

The full code listing for used for this article is as follows: 

1:  #include "SoftwareSerial.h"  
2:    
3:  SoftwareSerial ss(8, 9);  
4:    
5:  void setup() {  
6:   // put your setup code here, to run once:  
7:   Serial.begin(9600);  
8:   ss.begin(9600);  
9:  }  
10:    
11:  void loop() {  
12:   // put your main code here, to run repeatedly:  
13:   if (ss.available())  
14:    Serial.write(ss.read());  
15:   if (Serial.available())  
16:    ss.write(Serial.read());  
17:  }  




Wednesday, 5 August 2020

Serial Communications With Arduino

 This article is going to cover the topic of serial communication between an Arduino and another device. There are plenty of very good examples in the Arduino IDE that help you get to grips with the basics, but for this one we are going to do something that could actually be useful. To do this we will be using the following:

  • Neo-6M/GY-GPS6MV2 GPS Module
  • Arduino 2650 MEGA
  • CH340E USB to TTL adapter
  • breadboard
To start off with, we can illustrate a very simple example of serial communication taking place. The GPS module we have here is a self contained unit, once it is powered up and has its antenna attached, it will start to look for satellites and begin printing out its status via serial communication. I don't need to do anything at all for this to happen, however in order to read this data, we must connect a TTL/serial terminal to the module itself.

USB to TTL on left



This is where the USB to TTL module comes in to play. We can attach the serial port on this device to the serial port on the GPS module and connect the lot up to a computer using a USB cable. Once done, you will be able to use a terminal to connect to the serial port and view the raw GPS data in the form of NMEA sentences.

So, lets get started on the easy part of connecting the USB to TTL up to the GPS module. If you don't already have pins installed on these modules, go ahead and solder them in now, once done you want to put them side by side on the breadboard, its probably a good idea to use the outer most pins on the edge to seat these components.

Before doing anything else, lets make sure that the USB to TTL adapter works, and that you can use it. To do this, connect a USB cable to it and your computer, if this is the first time you are doing this your OS may tell you it is being installed, so wait for that to take place. If not, then it should just give you the noise to tell you it has been connected.

We can verify the connection by looking at the available ports your OS has available. On Windows, there are a couple of ways to do this. The best way is to go into Device Manager and look under "Ports, COM & LPT". You will see your adapter listed here if it is present, mine looks like this:

USB to TTL adapter highlighted

Note that port number down, it probably wont change and you will need it later. For now, we can disconnect the USB cable and get to work setting this up.

We need to power the GPS module, it is 5v tolerant but for right now lets run it at 3.3v - we can get this from our USB connection. Simple connect a wire between the 3V3 pin on the USB adapter and the VCC pin on the GPS module. Connect a ground wire accordingly.

Next, we need to connect the TX and RX pins to one another. When you are trying to transmit data between devices like this you need to connect these pins to their opposite.

This means you connect RX to TX and TX to RX. 

Doing so means that the device transmitting is always transmitting to a connection that is receiving and vice versa. So lets connect the TX and RX pins together, take a wire and connect TXD on the USB adapter to RX on the GPS module. Next connect the RXD pin on the USB adapter to the TX pin on the GPS module.

You need to be careful that you do not accidentally connect one of the serial pins to a power supply by mistake, this could damage your components.

Once you are happy with your connections, you could have something like this:


All we need to do now is hook up the USB cable and connect to the serial port. The best way to do this if you are using Windows is to get hold of PuTTY. Its a fantastic, free SSH and Telnet client that pretty much the entire world uses I think, you can download it from here.

So, to get this up and running, open up PuTTY. You will be greeted with a screen like this:


Make sure you have Session selected under Categories on the left, this is the highlighted field in the top left. Then select the Serial radio button, highlighted on the right. You will need to enter your COM port number here, I have entered 12 as this is the port number that has been assigned. Once I am sure everything has been done, I go ahead and click on Open.

And hey presto, you start getting GPS data back in the form of NMEA sentences, just like this:


This data will keep scrolling for as long as you keep power flowing through this circuit. As time goes by, the module will receive more and more data from the GPS network and all of those missing fields will be populated.

And all of this has been achieved without writing a single line of code.

So how useful is this? Well, in general terms, if you have a device that pins or pads designated as "UART" or "Serial", then you stand a very good chance of hooking them up to something like PuTTY to see what, if anything, is being sent out of the device. This can be really useful if you have a faulty device, sometimes they write out the error state on a serial port which can be read from another device. You might even be able to write data back over that connection - for example I have a NAS that is faulty at the current time, I have connected it up in this way to see if there is a specific error message, or any other info being written to the port. Unfortunately in this case, nothing useful turned up - but I did discover that I can flash the device using ICMP - which will be really useful once I figure out how to do it.

But in the context of the module used in the example above? Well, the data we received from it were standard NMEA sentences. To a human, they don't mean anything, we cannot really decode them without help. So with some code, we can consume those sentences and turn them into data that we can use easily, like coordinates and other measurements that we can easily comprehend.

But this is a topic for another time...

Sunday, 5 July 2020

Using Transistors As a Switch with Arduino

 Recently, I have had reason to look into switches and how they can work with Arduino, and other popular MCU's.

This is part of a larger piece of investigation that is looking into buttons, sliders, potentiometers, switches etc as inputs whilst I think about how to make my own keyboard.

Of course, everyone has heard of a transistor. We all have some form of awareness as to how important they are with regards to the evolution of technology and computing. But what is a transistor really? Anyone with a background, or an interest in computing will probably tell you that they are used to calculate things on a CPU, and they are correct - but this isnt what transistors are limited to.

I am not going to go into the science of transistors here or how they work on a microelectronic level, there are plenty of other blogs and articles who have done a much better job than I could ever do. What I am aiming to do here is to give a quick guide on how to pretty much use a transistor as a switch, how to connect one up and how to control one in the code.

Transistors basically can do two things; they act as switches and they can help amplify signals. And they do this by controlling the current flowing through them. However today, I am only going to be talking about how they can be used as a switch in this article. You may be asking why would you want to use a transistor as a switch? There are no physical controls, so you would need to programmatically control it - and that's the beauty of using a transistor as a switch.

One really good example of how this can be used could be this - you have a light somewhere that you want to turn on when it gets dark. You build a circuit with a lamp, and a light sensor. When the state of the light sensor reaches a certain point, you then want the lamp to light up. So you can use a transistor to act as the switch to do this.

Naturally, all of this would require an MCU of some type as well as some code, but it really is a nice little example of a potential application.

One of the neat features of using a transistor as a switch is, depending on your transistor, that you may be able to switch on a circuit of a much higher voltage. This is because a lot of transistors are capable of handling a lot more voltage because of their amplification abilities.

Transistors typically come with three pins, which are cryptically called:

  • Collector: This is normally the current you are trying to control.
  • Base: This is normally the current you use for the switch. It controls the bias on the transistor.
  • Emitter: This normally goes to ground.
For the examples below, I will be using the following components:

  • 2x 1 kohm resistors
  • 1x red LED
  • 1x PN2222A transistor
  • 1x Pro-Micro/Arduino Nano MCU

Here is an example diagram to help visualise this:


On this breadboard we have a transistor acting as a switch to control the LED. When 5 volts is applied to the power rail, the LED will light up, if I remove the transistor from the circuit then apply power, the LED would not light up.

Why is this? Well, to explain this, lets look at the names of the pins in relation to the connections in the diagram. 

Starting from left to right, we have the collector first on pin 1. This has the LED connected to it, with a 1K resistor running to 5 volts. This part of the circuit represents the current we are trying to control.

The middle pin, pin 2 - we have the base. This is the switch itself, when enough current is passing through it, the switch is closed. When there is insufficient, or zero current flowing through it, the switch is open. This controls the flow of current through the collector - this means when the switch is closed, current flows through the collector and the LED lights.

On the right, we have the third pin, which is tied to ground.

If you construct this circuit, there are two ways to test it. Firstly, remove the transistor from the circuit and apply power - the LED should be off. If it is on, then you are passing power to the LED without the transistor controlling it.

Second, disconnect power from the base, this should turn off the LED. If it doesnt, then again - you are probably passing power to the LED outside of the control of the LED.

Now, the above shows a transistor controlling current to an LED using 5 volts, but remember when I said they can also be used to control the current in circuits that require a higher voltage? We can create an example of this as well, but this time using 3.3 volts to control the transistor whilst still using 5 volts to light the LED:

All that has changed in this example is that we are now applying 3.3 volts to the lower power rail as well as 5 volts to the upper power rail. When the power is connected, the LED will light up.

One point to note here is that using a transistor in this setting is rather pointless. All this circuit does is provide power to an LED. This can lead to some confusion  when building such a circuit for testing or educational purposes.

So how about we create the classic "blink", but this time using our transistor? To do this, we are going to need to use a micro controller, for this example I am going to use a Pro-Micro/Arduino Nano using 5 volts. This means we can keep our initial breadboard design the same, more or less.

All we need to do is alter the way the transistor is biased. Instead of simply being powered directly from the power rail, we are going to connect it to a GPIO pin:


This is the same circuit as the one I initially built. It is orientated differently to accommodate its one difference, and that difference is how we are controlling the base on the transistor.

Previously, we were simply providing it with current, which caused the LED to be illuminated for as long as power was available. However in this example, we have connected the base to pin 2 on the Nano. Unless you make it happen, pin 2 will not be high, which means if you create this circuit and power it, the LED will not light up.

So, on to the the classic "blink", to achieve this we need to write a couple of lines of code, the whole thing is this:




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
void setup() {
  // put your setup code here, to run once:
  pinMode(2, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(2, HIGH);
  delay(1000);
  digitalWrite(2, LOW);
  delay(1000);
}


The setup for this is simple, we just need to define the pin we are going to use to control the base. In the diagram we have it connected to pin 2, so that is what we define here. We need this to be used for output, as we will be sending a signal to the transistor.

The main body of the program should be familiar to anyone who has tried out the blink sketch that is used to test out various developer boards. We simply take pin 2 high for a couple of seconds before sending it low for the same amount of time.

This basically opens and closes the transistor as if it were a switch, if you try this out for yourselves, you will see the LED blinking on and off every couple of seconds.

Now, lets get in to some specific points that are worth mentioning:

Using resistors is essential. Not putting a resistor across a transistor in the way I have shown above can often cause your transistor to melt, it certainly did for me unless the ones I had were also defective. It is important to note that the resistors you use should be of the appropriate resistance for your load - it wont always be 1 kOhm.

The examples above use an Arduino Nano, but everything here is also compatible with the cheaper Pro-Micro developer board. The only difference between the two boards is that one provides a 3.3 volt rail and the other doesn't.

Using a GPIO pin to control the biasing of a transistor is the win here. The state of the transistor can be governed by the state of a separate sensor(s), the result of a programmatical state or pretty much anything that is capable of changing the state of that pin.

For me, it was fun but a little frustrating learning about how transistors work. Writing this blog entry has been part of my learning process and perhaps someone will find it useful in the future themselves :)

Friday, 3 July 2020

Creating a 5 Volt DC Power Supply

 Just over a year ago I bought myself a robotics experiment kit from Amazon to play with during some downtime.

Naturally, a lot of us have had a lot of spare time (sort of) on our hands lately. So this gave me the opportunity to get this kit out and start playing around.

On opening it up, I discovered that it wasn't just a robotics kit, it was actually an Arduino based experiments kit. For those of you who don't know, Arduino itself is an open source hardware electronics platform. The open source bit is how their kit works, naturally you need to buy the hardware itself - or if you are skilled enough, you can make it yourself from the schematics and tools Arduino provides.

You can get more information about Arduino gear on their site as well as browse their store. I need to point out that I am in no way affiliated with Arduino, or get anything for writing about them.

In fact, it is often cheaper to browse eBay for Arduino clone boards than it is to buy the official ones, but that is a story for another day.

Now, back to the point. Once I had finished all the experiments described in the kit, I decided to try my hand at building some actual devices for myself. Of course at this point, I wasn't quite sure what to build, but I knew one thing, what ever it is I decided to build, it would need to be powered in some way.

One of the interesting things I discovered working with these electronics is that pretty much everything, including consumer electronics, runs from a DC power source. This means when you are building something, powering it from a wall outlet or a battery is usually interchangeable. The work you have to put in is how you condition this power source (for want of a better phrase).

To do this, we need to use a voltage regulator. A voltage regulator is an electronics component that is designed to control the forward flow of power from a power source, like a USB lead or a battery, onwards to your circuit. Wikipedia has a very good article on the subject here if you are a newbie like me and want to learn some more. In their simplest form, they will have three pins, voltage in, voltage out and a ground pin.

When building my own power supply, I wanted to use the same voltage regulator that came with the micro controller that came in my experiments kit - this was a Mega 2650. In order to find out where the voltage regulator might be (don't forget, my knowledge of electronics is very basic at this point) I referred to the boards schematics. I don't really understand how to read these very well at this point, but was easily able to see where the power for the board comes in, you can take a look at them here the power input is in the top left hand corner. After googling the name of all the components, I found what I was looking for, the MC33269D 5. This little guy is intended to take a DC current through the barrel connector and drop it down to 5 volts DC for the board to operate. Most people will never use this method though, as most of us will be powering the device via USB, which will also give you 5 volts DC.

However, when I went to look for this component on my board, it was missing. Mine seems to come from a company called Elegoo, which are a good place to get hobby electronics kit, so wasn't a cheap clone. In its place, we have an AMS1117-5, after a quick search I discovered that this is also a 5 volt DC regulator, I also found the same component on a few other boards I have. So it made sense to build my power supply around this component, it is cheap and readily available from places like eBay, Amazon as well as Mouser etc.

Another new thing for this bit of work that I am using is a tool to help me plan and design my build. Previously, if I was working on a largish experiment on the breadboard the most work I would put in to designing something was maybe a scribble in a notepad. That's fine when you can change any wire or component when ever you like, but when you are soldering things down you want to be 100% sure that you are putting the right thing in the right place and its orientated in the right way. Otherwise you can ruin a whole build and you may need to start from scratch... This is the voice of experience talking.

When looking for examples of Arduino circuits, you will often run in to these wonderful little images that simulate the layout on a breadboard. I wanted to use this in my posts going forwards, so I tracked down the tool used to make them. Again, I am not affiliated with this company, and I dont get anything from them and you need to pay for this tool, but it is available from Fritzing. In my humble opinion, the license is very cheap for what you get and for those who are inclined, you can download the source for free and compile it yourself. However I am not going to go into that here. This isnt going to be a tutorial on how to use Fritzing either, its a really easy to use package and is essentially drag and drop. As a tool for helping me with my little builds, it has been extremely helpful and has enabled me to learn more about what it is I am doing.

So, lets get started by creating a new design and putting a voltage regulator on it. Fritzing doesnt have a dedicated symbol for the AMS1117, so a search for this will give you pretty much nothing you can use. However if you search for 1117, you will get something called a "V_REG_LD1117VXX". This will do for the purposes of design, layout and even construction, depending on how you build this. The LD1117 precedes the AMS117, so lets get this out on to the board:

Before we go any further, we need to take a step back and address reality here for a second. If you found this article after looking for ways to create a 5 volt DC power supply for real then we need to talk about the package the AMS1117 family comes in. For the sake of illustration, I am using a TO-220 package to represent the voltage regulator. In reality, the AMS1117 family are all in the SOT-23 package (to the best of my knowledge). This is a lot smaller than the one pictured here and while it is possible to solder one of these by hand to some 2.54mm pitch protoboard, you are not going to be able to use one on a breadboard easily.

However, you can get adapters that will allow you to mount pins to a SOT-23 package, these are basically SOT-23 to DIP adapter plates. You can get them from all the major stockists online, but I found the cheapest place to get them so far is eBay, an example of some can be found here. This is what an AMS1117-5 looks like when it has been installed to one of these adapters, you can see how this will make things easier:




AMS117-5 next to SOT 23 to DIP adapter





You can use some flux to hold the regulator in place for soldering.


Try to solder one of the outer pins first. This will make the rest easier.


To finish off, you just need to add some 2.54mm pitch header pins and you are done. An easy way to solder components like this is to use a breadboard for support:

Some extra headers are laid flat at the other end for support.



Get some flux on and get one of the pins soldered into place, you can make sure it is square here before continuing to solder the remaining pins. Don't worry about getting it done perfectly at this point, we don't want the plastic on the headers to melt.

If you need to, go back over the joints to make sure they are even and then you are done. You should end up with something like this:





If this is the first time you have done something like this - well done, you just made your first very own component! You can now go on and use this in your own breadboarding as a 5v DC voltage regulator!

Now, back to the design. I need to make a few changes here to the symbols properties in order to make it more visually relevant to the build. The changes I make are as follows:


Now we need to push some power into this, you could assume that it is coming from a 9 volt battery, such as a PP9. Technically, you could connect the plus and minus pins from the battery directly to the battery and it could output a 5 volt supply, however that's not really how it works. We need to get a few more components in there before we can actually start using this. To start with, we want to make sure that power cant come back through the circuit and damage the battery - or whatever power source you are using. So we need to stick a diode between the battery's cathode, positive line, and the forward flow to the voltage regulator. A diode is essentially a one way gate, a current can flow through it one way, but not the other. This makes it ideal for protecting your power source.

With this done, I need to add in some capacitors. If you take a look at the NCP1117-5 datasheet, which is also very similar to the AMS117 family, you can see a breakdown of the output capacitance vs the  equivalent series resistance (ESR). Output capacitance here refers to the capacitors we need to put in to the circuit as power leaves the voltage regulator and from looking at the graphs on page six of the datasheet, we can see that a 100uf electrolytic capacitor flowing to a 100nf ceramic capacitor will provide what we need. This will help smooth out the flow of power as it moves through the circuit - I am also going to do the same thing as power goes in to the voltage regulator as well for the same reason.

Next up is to simply add something in to indicate that there is power running through the circuit, this can easily be done with a 1k resistor and a red LED. The completed breadboard could look something like this:





Naturally, this probably isnt the best way to illustrate the layout. I am still getting used to the tool, but it certainly makes you think about what you are doing before you do it and why you are doing it. For the above to work, you simply need to provide a DC power source greater than 5 volts on one end. The LED will light up to show the circuit is working, to test it you can get your meter out and measure the incoming supply before it hits the voltage regulator to see what is being fed into it. The design above ends in a screw terminal providing both positive and negative, you can measure here as well to see that you get a steady 5 volts, or there about. 

Don't worry if it is slightly under or over, what we need to check is the stability of the voltage. If you are seriously over or under 5 volts, then it is highly likely your regulator is either broken, or an incredibly poor quality copy.

Now, if you want to, you can go ahead and build this on a piece of protoboard, but - before you do, why not model that in Fritzing as well? You can actually design on protoboards of different types in this application as well as use a breadboard, so if you are like me, you can design what you want on screen first before you commit it to the board. As long as it has been designed correctly - which you test out on the breadboard first - all you need to do is make a physical copy. Its also good for documenting what you have done if you commit your work to source control.

The protoboard version of this build could look like this:


The board I ended up making looked like this:


When designing the protoboard version in software, I specifically used the same size and layout that I have for in my collection of physical protoboards. My soldering isnt great, neither is my use of space, layout etc. Also, please note that I didn't install the LED, despite putting the resistor for it in place.

However, this works. I have feed it up to 10 volts so far and it has maintained a steady 5v DC with very little heat. This is a relatively small build, if you look at the photo this is being propped up by a pen, the whole board is about half the size of the pen, so it gives you some idea of scale.

But, it wont stop here. There are a couple of improvements that I can think of already, such as adding a switch. It would be good to see how small I can get this as well.

One interesting thing to note about this design is that you can swap out the voltage regulator for the 3.3 volt version and it will still work. You don't need to change the capacitors. I guess you could probably make a switched power supply that could let you select either 5 or 3.3 volts.



Sunday, 15 September 2019

Creating My Own NAS - Part 2:Getting the right motherboard

In part one of this series, I discussed the reasons behind wanting to use FreeNAS as the basis for a DIY NAS solution in my home office/lab.

I finished up the last article by saying I would concentrate on the motherboard component of this project next as I felt that this would probably be the trickiest part of the build.

The specs for the overall system are not mind blowing, they dont need to be as I am not going to be using this as a critical server and I dont need it to be particularly powerful when it comes to the level of compute that I would like it to do. Also, I am trying to keep the costs down here whilst at the same time provide a flexible and dynamic base for the hardware itself.

Going into this build, I already knew I would want a motherboard that would be comfortable in the server role as well as being able to get all of the features associated with server activities built in. My current NAS is supposed to respond to WOL magic packets, but this functionality is shaky at the best of times, I know it works well on the majority of servers I have used in the past so it kind of makes sense that the feature should be more dependable on a motherboard designed for this purpose.

I also wanted to have the ability to have more than one actual CPU, a dual processor based system would again give me more flexibility when it came to the level of compute this thing has once it is up and running.

So, after scouring eBay for a suitable solution, I came across the Gigabyte 8IPXDR. This cost less than £40, so I consider this a pretty good catch for what I intend to do with it and should have the extensibility I need for the build. It is also a server motherboard in the ATX form factor that even came with a back plate, which will be immensely useful for keeping out all the dust and for keeping things quite. The only bad thing I can think of right now is that this is an ATX-E motherboard, the listing didnt mention this fact, and I only have an ATX case. On looking at the case, its pretty huge, so might accommodate this board, I dont know yet as I haven't gutted the case to see if things will fit.

This is also a dual CPU motherboard, so it meets the criteria for providing more flexibility when it comes to the processing power. One other fact that was missed off the listing is that it has two Xeon CPU's sat in both sockets - this is a bargain, although I am not sure what CPU's they are exactly. From Googling the numbers on the CPU's themselves, they may be 6-cored running at 2.5Ghz each. If this is the case, then I have grabbed a bargain indeed.

Sadly though, it doesnt have any on-board SATA interfaces, so I will need to obtain a SATA controller specifically for these drives. Fortunately, FreeNAS is compatible with a large number of SATA controllers out of the box and I have already begun looking for one that will work with this board.

This brings us on to the connections the board has itself. Because of the time it was made, it doesnt have PCI-E slots on board as standard, which is a bit of a shame but nothing that will effect the performance of the system when it is built. Instead, it comes with a mixture of PCI-X and PCI slots, which I think was the practice at the time. This means that the SATA controller I will get can be of the PCI-X format, and can also be a 64bit card - the board has one slot for a 64 bit card.

It also support SCSI RAID, although I dont think I have any compatible drives for this, unless one of the many drives I have in an old SAS array (that doesnt work) is compatible - it isnt important for this build right now as I am trying to make use of my SATA drives. There is also a pair of IDE connectors and an interface for a floppy, I have some old IDE drives that can go in this at some point and who else feels like a computer isnt a computer without a floppy drive?

It has two built in gigabit Ethernet ports, which is great as I will make use of them and on board ATI graphics, so the display should be pretty good as well.

So, what is happening next? Well, I will need to get that SATA controller card for definite, without it the build stops in its tracks. I am going to try and source a 64 bit PCI-X example of one, mainly because I have not used this standard before and I am curious. Also I will need to get some memory for the board, it can support upto  12GB of installed ram - but it needs to be ECC DDR 266Mhz memory. There are six slots available, however I very much doubt I will ever need to go that high for this build, 4GB should be plenty for our needs. Getting a pair of coolers for this board is also on the cards, whilst it came with free CPU's my luck didnt run as far as free coolers and I also need to check that the PSU in the case I will try to fit this to is compatible with this board.

And then there is fitting the board into the case itself, if that doesnt happen then I am going to need to get an ATX-E compatible one, and I am hoping this doesnt happen...

So, the next part should cover the SATA controller once I have bought it and an update on how it went fitting the board into the case.

Wednesday, 11 September 2019

Creating My Own NAS - Part 1: FreeNAS

For the last five or so years, I have been happily using a Synology DS215J NAS on my network to handle all of my off machine storage.

I love this device, it can accommodate two SATA drives in a number of RAID configurations to ensure that your data is securely stored. Right now, I use mine to archive important files as well as to act as a media server.

Synology provides an OS environment on the device itself that is highly configurable and one that has an active ecosystem of first and third party plugins to further extend the capability of the device itself. For instance, you can quite happily use this device as a full blown webserver, running PHP and POSTGres or as a CRM portal using Sugar, the choice is extraordinarily large.

For my needs, I make use of the media server plugins, this serves up all of my music and video across my network and any other device that can connect externally. I also have a cloud storage plugin that allows the device to connect to my various cloud storage solutions, OneDrive, Google etc, and sync files between these locations to ensure that I never lose my important data.

However, I have found myself in the position where I would like to upgrade my current solution in order to add more disks - I can have a max of two, and to increase the performance of the media capabilities - the CPU and resources on the box often get maxed if there is a lot of trans-coding.

I would have liked to buy a more capable version from Synology, but these things start getting expensive when you want to have more expansion options for disks and I just cannot justify spending that amount of money out for a device like this when I have other things I could spend the money on.

After doing a bit of investigation into other products I learned of something called FreeNAS. This is an open source storage OS specifically designed for, well, storage. It is intended to provide a complete and fully featured OS that supports NAS operations. All you need to bring to the party is your own hardware and you are up and running. This is an important point to note - in many consumer NAS solutions, you mainly get a rather under powered desktop PC that has been adapted for use as a NAS, for example the CPU in my DS215J is a Marvell Armada 375 Dual Core running at 800 MHz, it also has just 512MB of RAM. This is pretty weedy, even by the standards of five years ago.

The comparable model available now is the DS218+, which is a significant upgrade on my model and comes with a dual core Celeron running at 2.5Ghz and 2GB of RAM, a massive increase compared to what I have now - but this still has the same physical limitations as my current model with almost no ability to upgrade the memory or connectivity.

Now, FreeNAS allows you to install the OS on pretty much any hardware that is supported - you could run this on an old desktop PC that has IDE drives if you wanted to and it would work as a NAS, albeit a slow one by today's standards - but the upshot is that you get the sensibility that comes with a PC.

Like pretty much any guy of my age, I happen to have an old PC lying around - it serves as a stand for a lamp at the moment. I haven't used it in years, as far as I can remember it has an AMD Athlon CPU in it and what was a very capable graphics card from the mid-2000s. However, I dont plan to use any of that gubbins, I am interested in the case, its all aluminium and black (no windows, not that tacky) and takes a full sized ATX board. So I plan to gut this and source a second hand server motherboard to act as the basis for a new NAS build, one that should be able to take full advantage of the technical features available to FreeNAS as an OS.

FreeNAS itself is an OS based on FreeBSD, which doesn't need that much explanation for the purposes of this article. It also offers a number of features you would find on any enterprise level storage OS component, such as full disk encryption, RAID and backup that is compatible with many different providers. Additionally, it is based on the ZFS file system, which means it can handle snapshots and replication - again these are things you would find in any serious enterprise storage solution, but are neatly delivered to the hobbyist here.

As a result of this, it is possible for someone to create a custom NAS on their network at home that can handle all of the file-sharing, media serving, backup and replication that might be needed to keep an entire families worth of devices running hassle free. Not only that, but due to the fact you can install this on off the shelf hardware, the extensibility of the solution is only limited by your own finances and imagination. My current NAS has one gigabit LAN connection, but the new one I am about to build, why not throw in two 10GBE connections that are teamed? Probably wont do that though, lol.

So, for this little project I pretty much have everything I need to get started. I have a case and all the optical drives/floppy drives I need. I might need a new PSU, but I am going to get the following:

1 x server motherboard: This will be a second hand one from eBay. Nothing too old, but nothing too expensive either. This is my first time doing one of these builds, so I will refrain from going full on and getting a stupidly fast system, given that I dont need one so powerful.
1 x SATA controller: depending on the motherboard I get, I might need to obtain a SATA controller. This could be the case if the motherboard I get is not young enough to have this on board, right now I am assuming that whatever I get will support SCSI under RAID - but I dont have any SCSI drives (but I do have a stack of SAS drives...) plus SATA is a better choice for future drive upgrades. I may also want to have an NVME solution in here as well to boot from, this is something I will need to consider.
2 x CPU's: I am getting a server motherboard, so why not try getting a dual socket one? I was a teenager in the 90's, so I can remember the dream of owning a dual CPU PC for gaming back in the day, I know I dont need two CPU's these days but doubling up the chip count will also double my core count. This seems like an economical way of getting as much performance out of the setup as I can.
RAM: I have some RAM now, but I dont know if it is going to be suitable for this build, so depending on the motherboard I get, I made need more. But right now, I think I have 4GB of RAM that might be suitable for this.
HDD's: I have a stack of SATA drives I can throw in this baby from the get go. Most of them are 500GB drives, which will be fine for testing and getting the set up correct. I also have one 1TB drive I can throw in as well, but it will all depend on how the build will go and what sort of SATA controller I will end up getting, i at all.
1 x PSU: I have an ATX PSU right now, but I have no idea if this will be suitable for the build, so probably I will need to get another.

The first component I will source is the motherboard, this will pretty much determine the overall specification of the device and how much money I will need to spend on other components for this project. I want to keep the price as low as I possible can, naturally, so it will be scouring eBay for me until I find something suitable.

Part 2 should follow this one pretty quickly and will focus on the motherboard search.