Electro_pet

tl;dr

I got inspiration for this project from the petduino. The petduino is a great project to get kids into coding and electronics. I thought I would have a go and see if I could add some more features to it. Also my daughter was really interested in the 8×8 led matrix.

I started with a Arduino Leonardo added a 8×8 led matrix, piezo speaker and a few buttons all that can be found on a petduino, Also I added a gyro and a hall effect sensor. I wanted to get enough features into the design but I didn’t want it to suffer with feature creep so I added an expansion port or as I like to call it a hat.

Hardware

Hardware list

  • Arduino Leonardo
  • 8×8 led matrix I2C
  • piezo speaker
  • MPU-6050 gyro
  • A3144 hall effect sensor
  • Right angle button
  • AMS1117 3.3v regulator
  • Switch
  • Power bank charging/boost circuit
  • JST-PH male/female battery connector
  • 10k Ohm resistor
  • 330 Ohm resistor

This board was a real challenge to fit everything on and still try to make it small. This was my first dabble into making something that was truly a 2 sided board, meaning that I had components on both side of the board. Having components on both side of the board was a mental puzzle, I had to flip the foot print on the LED matrix and the hall effect sensor since they were going to be on the “back” of the board. I put the 3v power regulator under the gyro, Probably not a great move since it will give out some heat but I haven’t ran into any issue so far. I also remove 4 unused pins off the gyro to save space when routing on the PCB.

The populated PCB (rev b) with battery attached

Top of electro pet, You can see the hat port and buttons

Top of electro pet, You can see the hat port and buttons

The left side, You can see the power bank charge circuit and the battery

The left side, You can see the power bank charge circuit and the battery

The right side, You can see the arduino and the gyro too

The right side, You can see the arduino and the gyro too

Lastly the button, Here is the power switch and piezo speaker

Lastly the button, Here is the power switch and piezo speaker

Power struggle

When I need to add battery to a project I used to use the circuit from a power bank. I moved on to use the common lipo battery charger circuits (tp4056) you find on ebay then adding a DC-DC boost converter (EP00169) to boost the battery’s voltage up to 5v. The problem with using the lipo battery charger and boost circuit is that they take up quite a lot of space even when stacked. With this project I really didn’t have enough space for these boards so I went looking on aliexpress and found a tiny lipo charger and even smaller DC-DC boost board.

The lipo charger circuit has the ME4056 chip set and measures just 12.3mm  X 10mm. You will need to search online for the DD08CRMB to find it.

DC-DC boost board I found was even smaller than the lipo charging board measuring just 11mm x 7.62mm.

I thought I had sorted out my power for the project with these 2 boards. I tried them before added them into the circuit and it successfully boosted the battery to power the arduino on the bread board and even got  it to charge my phone. So I went ahead and added it to the schematic and sent the PCB off to be made. When I populated the board and added the battery and found that the DC-DC boost wouldn’t power the project. I don’t know why this is I think it is to do with the way I wired up the lipo charger as shown below. What is even weirder is that the lipo charger would only supply around 0.9V to the battery.

screenshot-from-2016-11-12-142608

I cut my loses and decided to go with a power bank circuit, I striped the USB type A port off to save space but left the micro USB port. It’s a bit of a hack but I couldn’t change my board size because I had already sent off the files for the laser cut acrylic. I’m not too happy because the board now has 2 micro USB port, one for charging and one for uploading code.

The case

Since I was emulating the petduino I thought it would be fitting to go with a laser cut acrylic enclosure. I have used laser cut acrylic in a past project Portable pi. I do my designs in inkscape because its a free cross platform tool thats open source to boot.

I normally use RazorLab which seams to be the only place that does small batch laser cut material in the UK. They have a design temple you can download HERE which give you all you need to get started.

The files are available on my github HERE

Jpeg

Bunny ears and right angle arms

Jpeg

Fox ears with robot arms plus feet

The hats

Santa hat

This is what got me really excited about this project. I have been fascinated by the hacker con badges and after seeing the Queercon 2016 badge I loved the idea of having an expandable header with the boards in the shape of a hat.

The first hat I designed was a Santa hat. This was inspired by Dr Saar Drimer after hearing him talk about his funky shaped boards on episode 176 of embedded podcast. I only really needed a different shaped board so I drew up a santa hat in inkscape then used SVG2MOD command line tool to turn it into a board edge file. Here is a simple tutorial to get you started with svg2mod

– Draw outline in inkscape stroke style 1.0
– Don’t group drawing
– Change layer name to Edge.Cuts
– Save as .svg
– python svg2mod.py -i drawing_name_input_file.svg -o drawing_name_output_file.mod –format legacy –value Edge.Cuts

The board files for the santa hat can be found HERE

Oshpark order link HERE

Breathalyzer hat

Ive always been fascinated with the MQ-3 Alcohol Gas Sensor and made a Breathalyzer myself with it a few year ago so naturally I jumped at the chance to add a MQ-3 hat into the mix.

I originally ported the code straight from my last Breathalyzer project but ended up with weird bugs I couldn’t track down so ended up rewriting it from scratch which worked out better in the end.

It’s a very simple board that maps the pin-outs of the MQ-3 to the current pin-out of the hat.

Oshpark order link – https://oshpark.com/shared_projects/sawXGY2I

Github board files – https://github.com/facelessloser/electro_pet/tree/master/kicad_board_files/electro_drunk

Getting started with MPU6050

mpu-6050

MPU6050 library – https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050

Github code – https://github.com/facelessloser/electro_pet/tree/master/test_code/mpu-6050

There are quite a few IMU/gyroscope that you can use with the arduino, I picked the MPU6050 because looked to be the most used by the community which is always a good thing. There is plenty of example code out there to get started with. I’ve written some a basic sketch to read the XYZ axes


#include "I2Cdev.h" // I2C library
#include "MPU6050.h" // MPU6050 library
#include "Wire.h" // Wire library

MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
#define OUTPUT_READABLE_ACCELGYRO
bool blinkState = false;

void setup() {

Wire.begin(); // Start wire library
Serial.begin(9600); // Start serial
accelgyro.initialize(); // Start mpu6050
}

void loop() {

accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); // Read mps6050
Serial.print(ax); Serial.print("\t"); // Print X
Serial.print(ay); Serial.print("\t"); // Print Y
Serial.println(az); // Print Z

}

Getting started with 8×8 i2c LED matrix

ht16k33

Adafruit_LED_Backpack Library – https://github.com/adafruit/Adafruit_LED_Backpack

Adafruit GFX Graphics Library – https://learn.adafruit.com/adafruit-gfx-graphics-library

If like me you have used the old LED matrix that are driven by a trusty max7219. Don’t get me wrong I love these matrix’s because they are really cheap and easy to use with all the libraries out there, There only down side is that they are quite large. I really needed to have a matrix that was smaller than the max7219 driven ones so I could add more features later. I had a quick look around and found a i2c driven LED matrix that was just a little bigger then the matrix its self, The chip that drives this version is the HT16K33. Lucky for use its the same chip set used in the adafruit 8×8 LED matrix so we can use their library

I’m not going to give you any example code with this one because I think that the examples found in the library contain all you need get started.

Getting started with piezo

I think using a piezo speaker is the easies way to add sound to a project. What I love the most about the piezo speaker is that you can play RTTTL tones which are the old nokia ring tones that you can still find on the Internet. I found that THIS library worked with the arduino leonardo. Below is that example code to play a RTTTL ringtone.


#include <rtttl.h>

//const char song_P[] PROGMEM = "Ghostbusters:d=4,o=5,b=180:4c5,4c5,8e5,8f5,8g5,8p, 4a#5,4a#5,4f5,4f5,4c5,4c5,8e5,8f5,8g5,8p,4a#5,4a#5,4f5";
//const char song_P[] PROGMEM = "dkong_level:d=4,o=5,b=200:c6,32p,8d6,8p,f6,8p,8d6,16p,8c6,16p,8d6,16p,a#";
//const char song_P[] PROGMEM = "PacMan:b=160:32b,32p,32b6,32p,32f#6,32p,32d#6,32p,32b6,32f#6,16p,16d#6,16p,32c6,32p,32c7,32p,32g6,32p,32e6,32p,32c7,32g6,16p,16e6,16p,32b,32p,32b6,32p,32f#6,32p,32d#6,32p,32b6,32f#6,16p,16d#6,16p,32d#6,32e6,32f6,32p,32f6,32f#6,32g6,32p,32g6,32g#6,32a6,32p,32b.6";
//const char song_P[] PROGMEM = "DonkeyKong:d=4,o=5,b=200:8a#,8p,8d6,16p,16f.6,16g.6,16f.6,8a#,8p,8d6,16p,16f.6,16g.6,16f.6,8a#,8p,8d6,16p,16f.6,16g.6,16f.6,8a#,8p,8d6,16p,16f.6,16g.6,16f.6";
//const char song_P[] PROGMEM = "Dambuste:d=4,o=5,b=63:4f6,8a#6,8f6,8f6,16d#6,16d6,8d#6,8f6,4d6,8f6,8d6,8d6,16c6,16a#,8a,8c6,8a#.,16c6,8d6,8g6,8f.6,16d6,4f6,8c6,8f6,16g6,16a6,8a#6,4a6,4p";
//const char song[] = "AxelF:d=4,o=5,b=125:32p,8g,8p,16a#.,8p,16g,16p,16g,8c6, 8g,8f,8g,8p,16d.6,8p,16g,16p,16g,8d#6,8d6,8a#,8g,8d6,8g6, 16g,16f,16p,16f,8d,8a#,2g,p,SS,16f6,8d6,8c6,8a#,g,8a#.,16g, 16p,16g,8c6,8g,8f,g,8d.6,16g,16p,16g,8d#6,8d6,8a#,8g,8d6, 8g6,16g,16f,16p,16f,8d,8a#,2g";
const char song_P[] PROGMEM = "Tetris:d=4,o=5,b=200:e6,8b,8c6,8d6,16e6,16d6,8c6,8b,a,8a,8c6,e6,8d6,8c6,b,8b,8c6,d6,e6,c6,a,2a,8p,d6,8f6,a6,8g6,8f6,e6,8e6,8c6,e6,8d6,8c6,b,8b,8c6,d6,e6,c6,a,a";

unsigned long printedTime = -1;
unsigned long printedPeriod = 500;

ProgmemPlayer player(13);

void setup(void)
{
Serial.begin(115200);
player.setSong(song_P);
}

void loop(void)
{

Serial.println("First Play");

//play the song for the first time
player.finishSong();

Serial.println("Song rewound automatically");

//play the tune again, this time blocking per note
while(player.stepSong()){
Serial.println("Second Play");
}

Serial.println("Song rewound automatically");

//play the tune with no blocking
while(player.pollSong()){
tryPrint("Third Play");
}

Serial.println("Play has ended");
while(true){
//keep the thread in this loop - circuit now silent
}

}

void tryPrint(String msg){
if(millis() - printedTime > printedPeriod){
Serial.println(msg);
printedTime = millis();
}
}

Arduino code

Halloween sketch – https://github.com/facelessloser/electro_pet/tree/master/arduino_code/halloween

I started working on the electro pet back in august. I thought I would have it finished by Halloween, I think I would had if I didn’t have so many set backs. I recycled a few animations from my last years Halloween project. I didn’t have time to make a Halloween hat but I will try and get round to it next year.

Christmas sketch – https://github.com/facelessloser/electro_pet/tree/master/arduino_code/santa

I think the best part of working with the 8×8 led matrix is that its a real challenge to make animations/art for it. I don’t think I have done so well with the art for the xmas code as I did with the Halloween one but I think you will be able to recognize a few familiar faces. But I’m quite proud of the snow effect that I came up with.

Balance game – https://github.com/facelessloser/electro_pet/tree/master/arduino_code/game

I thought I would take advantage of the accelerometer and make a game. Its quite simple, all you need to do is pass it between a group of people without tilting it and setting off the alarm. I was quite surprised at how easy it was to code

Dice – https://github.com/facelessloser/electro_pet/tree/master/arduino_code/dice

Who doesn’t love a dice, And what makes this even better is that you have to shake it just like a normal dice.

Snow globe – https://github.com/facelessloser/electro_pet/tree/master/arduino_code/snow_globe

I basically just re purposed some of the dice code so you could shake it and them it would snow for a few seconds later.

 

Fails

Ive had a few fails on this project. The first one being that I wired up the switch wrong so it wouldn’t isolate the power to the battery, This was a quick fix with a cut trace and a bodge wire.

My second fail was the fact the the DC-DC boost wouldn’t supply enough power and that the replacement DC-DC boost didn’t play nice with the lipo battery charger board.

The third fail came was when I was transferring the parts from the old PCB onto the new one. I managed to desolder most of the other parts but when It came to the arduino I bit off more then I could chew. You can see how badly bend the board become when I was heading up the pins and trying to pull it off the PCB below

Protips

I wanted to add “hats” to this project, This would allow me to expand the pet and add new functionality. In the past when I’ve had a need for a female edge connection I’ve used long pin female headers and just bent them over at 90 degrees like in the photo below.IMG_20141024_090633

This works great but I had a better idea. My idea was to use SMD pads instead of though hole so you don’t need to bend the header over and should take up less space.

Another great idea is if you are trying out a new way of doing things that you are unsure of will work, Instead of adding it to your next project just make a tiny PCB to test it out first. If it doesn’t work out or needs tweaking you haven’t wasted an expensive PCB. If you make them small enough you can get them made for under a dollar.

Youtube – youtube https://www.youtube.com/watch?v=her_zHj1RqI&w=560&h=315

Video

Hardware walk through – https://youtu.be/YaZLp8Ud3Dk

Santa hat/Breathalyzer hat – https://youtu.be/ezkD5qb2R3I

Advertisements

5 responses to “Electro_pet

  1. “What is even weirder is that the lipo charger would only supply around 0.9V to the battery.”

    Sounds faulty to me. I use these guys and I assume they put out more than .9v (https://www.aliexpress.com/item/Free-Shipping-2Pcs-lot-5V-1A-Micro-USB-18650-Lithium-Battery-Charging-Board-Charger-Module-Protection/2046516502.html), as I’ve never had a problem charging mine.

    I’m really curious about why your boost converter didn’t work. I couldn’t find the model number you stated (EP00169). If it’s what I came up with on an Ali search (https://www.aliexpress.com/item/Free-Shipping-10PCS-LOT-DC-3V-to-5V-USB-Output-charger-step-up-Power-Module-Mini/32469556177.html) those guys only have ~600mA output, so you might not have enough current for the duino+LED matrix maybe?? Duino will run something like 200-300mA I believe.

  2. Pingback: Electro Pet plays Santa – OSH Park·

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s