Rechargeable Battery Power

I’ve quickly cobbled together a rechargeable lithium battery circuit and stuck it into a box with an Arduino, a temperature / humidity sensor and a temperature / pressure sensor.

It hasn’t exploded yet.

This was the circuit I used to test it was working (using the battery charger and step up DC-DC converter to power my flammable gas sensing circuit, because it was within reach).

Charging Circuit

This evening I re-wrote an Arduino program of mine that takes measurements from a DHT22 temperature / humidity sensor and BMP180 temperature / pressure to make it work with and Arduino Nano with an LCD screen attached. I’ve not used a Nano in ages, but sadly, I needed the 3.3v regulator to drive the BMP180. Hopefully it won’t be drawing much current and so not wasting much energy, after I went to the effort of using a reasonably efficient step up converter. I did check, and the voltage straight from the battery is also too high. Future plans include… not using 3.3v sensors.

Here is a video of the box running off the battery.

I’ll tidy up the circuit – perhaps move it from breadboard and a pile of bits onto protoboard, make the charging port accessible, add a power button, menu buttons, battery voltage monitoring, auto power down for low battery / after inactivity and perhaps add an external 1 wire bus for DS18b20 sensors. At that point I’ll document what I’ve done a little better.

An afternoon with the Chickens

We let the chickens out today and took a few photos of them causing trouble. One was perched on my arm and another made quite a leap to join her.

ArmChickens

Chickens say hello. They’ll do anything for mealworms. These two are called Chompsky and Goblin – they are both Rachel’s. Mine are a lot more shy, although Stuff climbed up on my arm today for the first time. Unfortunately, Chompsky then almost knocked her off and she decided she’d rather forage on the ground!

ArmChickens2

Three of the girls then decided that they wanted a mud bath. Grubby little things.

Dirt Bath

Bits and Bobs

Lots of of things arrived from China this week, most interesting thing is a number of lithium polymer battery charger boards from here

Battery Charger

I’m planning to use this as part of the power supply for arduino projects. This provides the ability to re-charge a 3.7v lithium ion battery of the type used in my quadcopters. I’ll then run the output terminals into a DC-DC converter, when they arrive, to get a steady 5v. The inspiration for this is in part from this interesting article, although I had ordered the chargers before I spotted it.

Lithium ion batteries do not like staying empty so it is probably sensible to stick a potential divider and monitor the battery voltage. When The voltage gets too low, it should be possible to shut down the circuit. For now, I’ve wired in a JSP connector (correct me if it isn’t, I find it difficult to find out exactly what connectors are called). While charging, a bright red LED is lit, once the device finishes charging, the red LED is extinguished and a blue one lights instead. I’ve checked the voltages on the batteries after charging, but haven’t done any substantial testing yet.

Battery Charging

I also got a number of other things at the same time – I got some more breadboard, because you can never have enough, a Raspberry Pi breadboard breakout, because I gave one of mine away the other week, some new little breadboard power supplies, because they looked like a better design than my existing ones, some SNES style USB controllers and some battery boxes.

Breadboard PSU

My existing breadboard power supplies cover quite a few rows of contacts. They also do not appear to supply enough current for my Z80 computer project, but as these new ones use the same regulator (AMS1117), I’m unlikely to have the same issues. It might have been something I was doing – I’ll investigate again at some point in the future.

Raspberry Pi Breakout

These Raspberry Pi breadboard breakouts are great for working with the GPIO on the Raspberry Pi without too much faff. I have used them for projects where I have no intention of making any custom boards – I do have the stuff to make up my own ribbon cables and have IDC board connectors, so this is always an option if I want to make something smaller.

Battery Box

Putting batteries into project boxes in a way that an end user will be able to change them without too much fuss has always been an issue for me. I really don’t like how project boxes cost as much as all the electronics held within, nor do I like that the ones with battery compartments cost three times as much. This is my attempt at finding a solution. Sadly, I’m trying to move away from 9v batteries, because they’re not really the best solution.

USB Controller

Hours of fun – I have now bought eight of these in total. Four to give away to colleagues at work who have recently obtained Raspberry Pis, and four of my own. These work straight out of the box with the Retro Pie image. Retro Pie boots straight into Emulation Station, with the bulk of the setup done for you. Unfortunately, it still takes a while to get ROMs sorted etc. but there isn’t really anything they can do about that without breaking the law! The Raspberry Pie 2 is able to run emulators up to and including the N64 and original PS, although I find it is really best at the SNES and various Nintendo handhelds.

Detecting LPG, Propane & Butane

As I previously mentioned, I got a number of gas sensors. The intention is to use one to build a gas leak detector for a neighbour who has no sense of smell and runs a burger van. After reading the datasheets for a number of possible sensors including the MQ-2, MQ-5 and MQ-6, I decided to use the MQ-6 as it seemed best suited. The MQ-2 is sensitive to smoke, which rules it out and the MQ-6 appears to be more sensitive to LPG than the MQ-5, judging by the datasheets. The sensors I have come on breakout boards. My MQ-6 board is powered from 5v and has a digital output with the threshold set by a potentiometer on the board in addition to the analogue output. The on board comparator (I’ve not looked into what form it takes) lights an LED when the gas concentration exceeds the level set by the potentiometer, but be aware that a digital LOW corresponds to a positive identification of gas, and a digital HIGH corresponds to the concentration being lower than the set threshold. The datasheet states that the sensor consumes <750mW, mine seems to be using something between 400 and 500mW.

MQ-6 Gas Sensor

I have been using an Arduino Pro Micro board because they are convenient for prototyping in breadboard as they have a built in USB port and a DIL layout. I may switch to a ATTiny85 or a ATMega328 in the future. The Pro Micro is built around the ATMega32u4 chip and can be bought cheaply from alibaba, or almost as cheaply using paypal from banggood.

Arduino Pro Micro

After writing some comments in an empty sketch to give me the structure of what I wanted to do, I wired up the sensor, along with an LED (unfortunately the Pro Micro only has LEDs for power, TX and RX) and a push-to-make switch to act as an “action” button. I later added a 2N7000 MOSFET, which I am using to switch power to the sensor – this is being used to reduce the power consumption after 10 minutes and reduce battery usage should someone forget to turn the device off!

20160206_144747

Quick diagram (ignore the colours in the photo, they’re misleading) :

Screenshot from 2016-02-06 18:14:43

The sensor seems to need bedding in and so the values I’ve used for alarm thresholds are only temporary. Once it stabilises (it is referred to as a “burning in” period elsewhere), I’ll re-visit the values.

The current code is as follows :

// LPG Gas Detector
// 
// Using the MQ-6, although with changes to detection values,
// you could easily use the MQ-5, or perhaps the MQ-2.
// No responsibility is taken for failure to detect gas.
// Samplerates are approximate for simplicity.
// 6th Feb 2016 version 0.1



int heaterPin = 9; // connect a MOSFET or transistor to this pin to
                      // drive the Heater
int DIn = 10; // connect the digital trigger from the sensor

int AIn = A0; // connect the analogue input from the sensor

int LED1 = 2; // LED

int action = 7; // action button

unsigned long stopTime;
byte heaterOffMinutes = 10;// time before auto power down heater
byte heaterDelayMinutes = 3;// time to wait for heater to start
//byte heaterDelayMinutes = 1;// time to wait for heater to start
byte samplesPerMinute = 30;// number of samples in a minute
byte reheatDelayMinutes = 1;// Time to reheat after low power mode. Should really be 3 minutes.

boolean debug = true;

int lowAlarm = 250;
int medAlarm = 375;
int highAlarm = 500;

void setup() {
  unsigned long heaterOff = heaterOffMinutes*60L*1000L;// min*seconds*ms
  int heaterDelay = heaterDelayMinutes*60L;// min*seconds

  if(debug){
    Serial.begin(115200);
  }
  
  delay(3000);

  if(debug){
    Serial.println("Setting up pins...");
  }
  
  pinMode(DIn,INPUT);
  pinMode(AIn, INPUT);
  pinMode(LED1, OUTPUT);
  pinMode(heaterPin, OUTPUT);
  pinMode(action, INPUT);

  digitalWrite(LED1, LOW);

  if(debug){
    Serial.println("Turning on heater...");
  }
  
  // Turn on heater
  digitalWrite(heaterPin, HIGH);

  if(debug){
    Serial.println("Waiting for heater to warm up...");
  }
  
  // Wait Three minutes before giving readings
  heat(heaterDelay);//heaterDelay in seconds

  // Record target stop time for auto heater off (save the battery!)
  stopTime = millis()+heaterOff;
  if(debug){
    Serial.println("Heater will stop at : " + String(stopTime,DEC));
  }
  
}

void loop() {
  // Go to sleep after 10 minutes? At least turn off heater.
  if(millis() < stopTime){
      if(debug){
        Serial.println(String((stopTime-millis())/1000, DEC) + " seconds until sleep. Taking Reading...");
      }
      int AVal = analogRead(AIn);
      boolean DVal = !digitalRead(DIn);// 0 is high
      if(debug){
        Serial.println("Digital is : " + String(DVal, DEC));
      }
      if(debug){
        Serial.println("Analogue is : " + String(AVal, DEC));
      }
      if(AVal > lowAlarm){
        if(AVal > medAlarm){
          if(AVal > highAlarm){
            //HighAlarm
            digitalWrite(LED1, HIGH);
            if(debug){
              Serial.println("Alarm! High");
            }
          }else{
            //MedAlarm
            if(debug){
              Serial.println("Alarm! Medium");
            }
            digitalWrite(LED1, LOW);
            delay(10);
            digitalWrite(LED1, HIGH);
            delay(50);
            digitalWrite(LED1, LOW);
            delay(200);
            digitalWrite(LED1, HIGH);
            delay(50);
            digitalWrite(LED1, LOW);
            delay(200);
            digitalWrite(LED1, HIGH);
            delay(50);
            digitalWrite(LED1, LOW);
          }
        }else{
          //LowAlarm
          if(debug){
              Serial.println("Alarm! Low");
            }
          digitalWrite(LED1, LOW);
          delay(10);
          digitalWrite(LED1, HIGH);
          delay(50);
          digitalWrite(LED1, LOW);
          delay(200);
          digitalWrite(LED1, HIGH);
          delay(50);
          digitalWrite(LED1, LOW);
        }
      }else{
        //NoAlarm
        digitalWrite(LED1, LOW);
      }

  
  
  }// end of stopTime if
  else{
    if(debug){
      Serial.println("Low Power mode");
    }
    //sleep mode instead of delay?
    digitalWrite(heaterPin, LOW);
    int y = 0;
    for(int x=0; x<30; x++){
      if(digitalRead(action)){
        y++;
      }else{
        y=0;
      }
      if(y>2){
        // Record target stop time for auto heater off (save the battery!)
        digitalWrite(heaterPin, HIGH);
        while(digitalRead(action)){
          //do nothing
          delay(100);
        }
        heat(reheatDelayMinutes*60L);
        stopTime = millis()+(heaterOffMinutes*60L*1000L);
        x = 30;
        if(debug){
          Serial.println("Heater will stop at : " + String(stopTime,DEC));
        }
      }
      delay(2000);
    }
    
  }
  delay(60000L/samplesPerMinute);

  digitalWrite(LED1, LOW);
  delay(10);
  digitalWrite(LED1, HIGH);
  delay(10);
  digitalWrite(LED1, LOW);
}

void heat(int heaterDelay){ // heaterDelay in seconds
  for(int x = 0; x< heaterDelay; x++){
    boolean btn = false;
    if(debug){
      Serial.println("Readings start in... " + String(heaterDelay-x,DEC)+ " seconds");
    }
    //Serial.println(String(x, DEC) + " of " + String(heaterDelay, DEC));
    digitalWrite(LED1, !digitalRead(LED1));
    if(digitalRead(action)){
      btn = true;
    }
    delay(1000);
    if(digitalRead(action) && btn){
      x = heaterDelay;
      if(debug){
        Serial.println("Warm up skipped...");
      }
    }
  }
}

If you spot any errors, please drop me a message!

As always, the most difficult part of this project seems to be identifying a suitable power source and box. I’ve been using my USB meter to gauge how much energy the circuit uses – I estimate that I  can run it with the heater on for 10 hours off four AA batteries. I’m struggling to identify a box that would easily allow the end user to change the battery without being forced to use a PP6 battery, which would be a waste of 4v. I’m not sure how accurate my little USB meter is, but it is very useful as I power a lot of my projects off computer USB ports or my USB battery packs!

USB Meter
My USB Voltage and Current Meter.

ODROID SSH Access

ODROID Desktop

I’ve been setting up my ODROID C1+ over the last couple of evenings. One thing I noticed was that SSH wasn’t working. When connecting in to the ODroid, I was receiving the response “Read from socket failed: Connection reset by peer”. I compared my ssh settings with my linux laptop and found that they were identical, and so I had a bit of a poke around on the internet. Finally, after lots of very complicated things that were a little invasive for the setup, and a number of workarounds that involved changing settings on the perfectly serviceable client device, I found a down-voted suggestion that someone try regenerating their host keys.

sudo rm /etc/ssh/ssh_host_*

sudo ssh-keygen -A

I gave it a go, and was delighted to find everything sprung into life and I now have a working SSH server on my ODROID device.

Odroid-C1+ and Gas Sensors

Today I’ve received a couple of things in the post. The first is an Odroid-C1+ SBC. This is very similar in appearance to a Raspberry Pi, the main differences being the board is blue, and a substantial heatsink over the processor and RAM. The board appears to be well made and sports a 1.5ghz quad core ARMv7 processor and a reasonably mature port of Lubuntu among other things.

ODROID-C1+
ODROID-C1+

 

I have to admit that I do not actually have any specific plans for this board, but the specifications intrigued me. A brief look at the board has so far shown that it boots reasonably quickly (I had to tweak the settings on the boot partition to get the video working correctly through a HDMI to DVI adapter – not too difficult as the boot partition is FAT32 (shows up on all popular operating systems) and they’ve kindly put a large number of options in comments so that you can just comment out the old settings and delete the “#” on the setting you need.

Kodi came pre-installed which was good for testing. No tearing during video playback which is better than my Linux Mint laptop’s default settings. Only issue is that it seems the GUI for the file manager is not hardware accelerated and is a little laggy. There is an eMMC connection on the underside of the board with is claimed to give a 4x disk speed improvement compared to an SD card. These eMMC modules are quite expensive (£20 for 8GB, £30 for 16GB), but it is nice to know that it is available if I ever need it!

Another package contained nine various gas/smoke/vapour sensors all the way from China. I’m planning to put something together to detect LPG for a neighbour who can’t smell properly and worries about gas leaking from the cooker. I got a full set of nine in a nice box with some dupont wires from banggood.com – terrible name, good prices.

I’m thinking that perhaps I should somehow attach the alcohol detector to my Paypal account to prevent drunken synth purchases…

 

BeebEm and Marathon in RetroPie

I’ve been setting up an SD card for my Raspberry Pi 2 with the latest stable version of RetroPie. RetroPie is a collection of emulators presented from a single interface that can be navigated easily with a controller. BeebEm is a BBC Micro emulator, and is not included as standard in RetroPie.

As I, and several of my friends grew up with BBCs, I decided that this needed sorting and so following these instructions, I was up and running in no time. I also added Marathon 2 and Marathon Infinity into the “Ports” section, using the method shown here. This second method is a lot simpler, but is only really suited to single games, rather than whole platforms with multiple games. For some reason, the original Marathon game did not work properly (loaded, but would not enter a game). I will return to look at it another time.

For those who do not know, the Marathon games were a series of games produced by Bungie in the 1990s (after Pathways into Darkness and Gnop, before Oni and Halo, at a similar time to the Myth series!). The games were fun to play, good to look at and had well written story lines. A rare thing at the time. Just before Microsoft bought Bungie, they kindly released the source to the Marathon engine and so a community project (called Aleph One)was born to update it and port it to new platforms. This is how, years down the line, I am able to play the games on a computer the size of a pack of cards, running on a processor derived from the follow on of the BBC Micro, using an operating system that it was never released for.

Marathon Infinity
Playing Marathon Infinity on the Raspberry Pi