Monday, 18 April 2016

Arduino-PID-Library online Trainer

PID seems to be a rather magical thing. I ported the Arduino-PID-Library to javascript so you can play with the constants in a simulator and and see the results immediately. Hopefully this will make people less scared about the tuning process.

In this simulator, you are Lara Croft driving a car. Using the sliders below you have to choose Kp, Ki and Kd to follow the green line as closely as possible, that is without overshooting or oscillating (so, not like now).

This PID controls the accelerator/decelerator of a car. There is some drag and the vehicle has a certain mass.

The X axis is time and the Y axis is the position of the car. Make sure she is at the right position at the right time

Can you help her? Good luck!



Position:

PID's output (accelerator):




Notes:


  • The car is simulated by using the following equations:
    • x(t) = v*t + 0.5*a*t^2
    • v(t) = a*t
  • The PID code is based in the Arduino PID Library by Brett Beauregard.

Lessons learnt:


There are 2 types of processes.
  • Processes that keep their last state (like in the level 1, a car on a flat road). These are called integrating processes, they don't need a Ki and the PID won't overshoot
  • Processes that feel an external force (car on a slope, something cooling down). These are called self regulating processes, they do need a Ki and they will overshoot when the external force changes

Credits go to Brett Beauregard for his excellent library and his great explanations in the diy-pid-control forum

Saturday, 20 February 2016

Monitor your fridge temperature

Ever wondered how efficient your fridge is?

Mine with a set point of 9 degrees needs to cool for 45 minutes(compressor on) and seems to keep the cold for another 45 minutes(compressor off). The temperature seems to oscillate ±1.5 degrees as you see in the pic.


I wonder how well other people's fridges perform. Should I change it? I wish everyone was posting their data! 


Here is a picture of my setup:


I am using a ESP8266 connected to an LM75 sensor. I am using a 5000mAh 3.7V battery connected through a step down voltage regulator to get 3.3V.

The device has been running for 37 hours thanks to using deep sleep. Every minute the ESP8266 was waking up, measuring the temperature, sending it to a server and then back to sleep. 

The consumption per wake up is: 5000mAh/37h/60 = 2.25mA

Just for laughs I'm going to elaborate on this server, it is just an old 'HTC Desire S' cellphone that is running Debian linux. This cellphone is now my cloud and it is running 24/7, it has installed PHP, nginx, mysql, samba, minidlna, ssh, avahi, and OpenVPN so I can connect remotely and have full access to everything. 

In order the deep sleep function I had to connect the XPD_DCDC with the reset pin, if you zoom into the ESP8266 you'll see the dirty hack (credits go to http://tim.jagenberg.info/2015/01/18/low-power-esp8266/ for the idea)



I find rather interesting what happened when the battery was running out of juice. The ESP seemed to work properly but the LM75 sensor was becoming more and more noisy


One would expect that the ESP would be the first one to notice the lack of power! The time stamps are generated in the server so this seems to imply that the ESP was doing its job at the right intervals.

If people show enough interest I will tidy up the code and upload it to github.

Sunday, 13 September 2015

Hacking an electronic price display, success!!

Somehow I found one of this tags (don't ask) and decided to hack it. The display is WF021-01 and you can find eink's datasheet here. Unfortunately this doc it in incomplete and it doesn't show the list of commands to control the display. Luckily I found many similar datasheets from other similar eink displays and noticed that many of those commands are the same across devices. I tried some of those commands and found the ones that work with my display. Tadaaa!





This is how the back of the device looks like:



I cant tell much about the epoxy blob, luckily the PCB has a bunch test pads that can be used to drive the display (I had to cut the traces to stop the main processor from interfering with my data):

This is what each test pad is for:


  • tp11: bs1(set this oen to ground so you can use the 3 wire interface a)
  • tp10: res
  • tp8 : d/c  (no need to drive this one if you set tp11 to ground)
  • tp7: busy
  • tp6: cs
  • tp5: d0
  • tp4: d1
  • tp1: vddi
  • tp18: gnd 


I am using an arduino to talk to the eink display, I'll post the code to drive it as soon as I clean it up a bit. Enjoy!





Tuesday, 23 June 2015

Simple nodemcu module to drive a nokia LCD (PCD8544)


I desperately wanted to hook a Nokia5110 LCD to my ESP8266/nodemcu. I wrote a LUA module but it was slow and it was taking too much memory, mainly because the font data needs to stay in the precious RAM.

It looks like anything I do ends up taking too much memory, so the way to go is to write modules in c and then invoke them from LUA. I am very pleased with the results, so here it is for you to use: Download (just for fun the lua module and the image are also included)


You can use it this way:
  • pcd.init()
  • pcd.locate(0,0)
  • pcd.print("Hello world!")
And if you want to display images you can do it this way:
  • pcd.init() 
  • file.open("image.bin", "r") 
  • pcd.printbin(file.read()) 
  • file.close()
I already sent a pullrequest to the nodemcu guys, it may not get accepted as the pins needed are hardcoded :/ 

Saturday, 5 October 2013

Software defined FM radio transmitter (Arduino + AD9850)

This video shows it all, take it away!


The frequency is generated by the AD9850 and the modulation is done by the arduino

The full code is here:
http://pastebin.com/YMErwwK3

The FM band channels are centered at certain frequency, in our case 90Mhz, any slight deviation of that freq (by a max of +/- 75Khz) will move the membrane of the speaker backward or forward, here is the bit of code that implements that. And this is the (unoptimized) modulation routine.
void playTone(unsigned int note, unsigned int duration ) 
{
  const double freq = 90 * 1e6; // transmitting at 90Mhz

  // play silence 
  if ( note == 0)
  {
    ad.setfreq(freq);
    delay(duration);  
    return;
  }
  
  unsigned long currentMillis = millis() + duration;
  while( millis()< currentMillis)
  { 
      ad.setfreq(freq + 75e3/2); // speaker's membrane backward
      delayMicroseconds(note);
      ad.setfreq(freq - 75e3/2); // speaker's membrane forward
      delayMicroseconds(note);
  }

  ad.setfreq(freq );
}

Credits go to:
Brett Hagman for the RTTTL tune player
Poul-Henning Kamp for the AD9850 lib

Friday, 5 July 2013

Minimal ECG using an Arduino and Xoscillo

First off, the picture :)


To display the wave I am using XOSCILLO, a very cool and open source tool (which I wrote :P) that converts your Arduino into an oscilloscope.

Circuit diagram

Here is the scheme, I am using the typical instrumental amplifier(ins amp) and then another op amp to get some more gain. An ins-amp is like an op-amps but with a huge CMRR, I am using a AD8221 which comes in a tiny small package, it's lead pitch is only 0.65mm, if you want to know what I did to create a simple breakout board please follow this link.

I'm using a single supply for the amps that comes from the arduino 5V pin, and I am creating a buffered virtual ground, this is really important.


Here is, a bit dark, a pic of the setup in the breadboard.


Tricks of the trade:

This is what makes the difference between a working ECG and a non working one :)

The main problem is that the device is so sensitive that it get interference from almost everywhere, specially the mains hum at 50hz). As you can see I got a clean signal, and I am not using any kind of serious filtering, note that xoscillo has a low pass filter and I am not even using it, so what are the tricks?

  1. Run it from a laptop and unplug the charger!
  2. Don't use a second monitor, the HDMI port will cause all sorts of high frequency interferences
  3. Get about 1 meter away from the laptop
  4. Buy some serious ECG electrodes, mines are "H124SG * Ø 24 mm", they come in a box of 50 and should cost about 11 euros. 

That's all, if you like it or build it or need help feel free to write a comment, it will encourage me to write more articles :)



Saturday, 22 June 2013

Poor man's MSOP soldering

MSOP stands for Mini Small  Outline Package, that means that width of 4 leads is just 2mm, exactly the width of a row in a stripboard... Let see how can we solder that though.

On a piece of wood we tape carefully 4 thin wires. We start my taping one wire and then taping again a second one at a distance of 2mm, take as much time as you need, this step is crucial, place on top the MSOP to make sure they have the right separation. If you need to make any adjustments use the blade of a cutter to move the wire. Good now you have the top one and the lower one. For the 2 inner ones, just put them in between and fix them with tape, then use the cutter blade to make sure they are all spaced equally


We place the MSOP on top and we tape it, then make the necessary adjustments in the separations of the wires. Once we are happy we tape the IC this time more tightly.
 Time to solder, use flux and apply the iron firmly as with any other SMD
Once we have one side done we do the other side, this time it will be easier since the other half is firmly fixed, time to correct the separation of the wires too.
 Once we remove the tape we check the back of the IC to make sure all looks good and clean.
 We cut the thin wires by just applying some firm vertical pressure with a cutter.

 Time to  place it on the stripboard, we carefully separate the wires and we insert them through the holes,
 And voila, the breakout board :)

Tuesday, 26 February 2013

Measuring inductances using an arduino


I just read this excellent article about measuring inductances:

http://reibot.org/2011/07/19/measuring-inductance/

The technique consists in measuring the resonance frequency of a LC circuit. Since this frequency is:

f = 1.0/(2.0*M_PI*sqrt(L*C))

By measuring f with the arduino and knowing C you can easily get L.

I modified the code so its much more precise, the original code is using 'pulse' to read half an oscillation. My code instead measures one whole oscillation by using an AVR's hw feature called Input Compare, this feaure starts and stops a timer that runs at 16Mhz.

Enjoy!


//measuring inductance using the higher precision input compare  
//based on http://reibot.org/2011/07/19/measuring-inductance/  
//capture Flag  
volatile uint8_t Flag;
void InitTimer1(void)
{
    cli();
    //Set Initial Timer value  
    TCCR1A = 0;
    TCCR1B = 0;
    // Input Capture Noise Canceller  
    TCCR1B |= (1 << ICNC1);
    //First capture on rising edge  
    TCCR1B |= (1 << ICES1);
    //Start timer without prescaller  
    TCCR1B &= ~ ((1 << CS12) | (1 << CS11) | (1 << CS10));
    TCCR1B |= (1 << CS10);
    //Enable input capture and overflow interrupts  
    TIMSK1 = 0;
    TIMSK1 |= (1 << ICIE1) | (1 << TOIE1);
    Flag = 0;
    sei();
}
volatile uint16_t Capt;
volatile uint16_t T1Ovs2;
//capture ISR  
ISR(TIMER1_CAPT_vect)
{
    if (Flag == 0)
    {
        //reset overflows  
        TCNT1 = 0;
        T1Ovs2 = 0;
    }
    else if (Flag == 1)
    {
        Capt = ICR1;
        //disable capture and overflow interrupts
        TIMSK1 &= ~ ((1 << ICIE1) | (1 << TOIE1));
        //clear pending interrupts  
        TIFR1 = (1 << ICF1) | (1 << TOV1);
    }
    //increment Flag  
    Flag++;
}
//Overflow ISR  
ISR(TIMER1_OVF_vect)
{
    T1Ovs2++; //increment overflow counter  
}
//13 is the input to the circuit (connects to 150ohm resistor)
//8 is the comparator/op-amp output.   
//reibot.org for guide  
double pulse, freq, inductance;
//insert capacitance here. Currently using 2uF  
double capacitance = 2E-6;
void setup()
{
    Serial.begin(115200);
    pinMode(8, INPUT);
    digitalWrite(8, LOW);
    pinMode(13, OUTPUT);
    Serial.println("Why hello!");
    delay(200);
}
void loop()
{
    digitalWrite(13, HIGH);
    delay(10); //give some time to charge inductor.   
    digitalWrite(13, LOW);
    delayMicroseconds(15); //make sure resonance is measured  
    InitTimer1();
    delay(100); // wait for ICR to read once cycle  
    pulse = (T1Ovs2 * 65536 + Capt) / 16.0;
    if (pulse > 0.1)
    {
        freq = 1.E6 / pulse;
        inductance = 1. / (capacitance * freq * freq * 4. * 3.14159 * 3.14159);
        inductance *= 1E6;
        Serial.print("High for uS:");
        Serial.print(pulse);
        Serial.print("\tfrequency Hz:");
        Serial.print(freq);
        Serial.print("\tinductance uH:");
        Serial.println(inductance);
        delay(20);
    }
}

Sunday, 3 February 2013

SMD if there is a will there is a way

I couldn't wait for my breakout boards to arrive! I hope this encourages others to do some smd soldering... I used some rosin soldering flux from radio shack and a regular solder.

SMD breakout board

Wednesday, 16 January 2013

Virtual MSX disk drive


When I was a kid I had an MSX, a SVI-728 to be more precise, it's just a Z80 based computer with 64Kb of RAM. Mine used cassette tapes to load games and the loading times were eternal not to mentioned all the loading errors that required restarting the load from the beginning.

Other friends of mine had an MSX with a disk drive but I got still stuck with the tapes :-(

So... Revenge! I decided to build my own disk unit :-)

MSX's with a disk drive come with a disk BIOS that handles all the disk operations, from the lowest level (i.e.: read sector 23) to extending BASIC with new commands to list the available files in the disk, formating, deleting and creating files, and so on.

My first step was to get a disk BIOS from a MSX with a disk unit and patch the sector reading/writing routine so instead of talking to a disk unit, it would talk to another device, an Arduino.

Unfortunately I can't fit an 720Kb disk in an Arduino but since it has a USB connection it can ask my PC to get that sector form an certain disk image in my PC's hard's disk and send it thought the USB cable.

For that I need some gluing hardware between the MSX and the Arduino, here is the pic of the setup

Breadboard with arduino-msx gluing logic

And here are the schematics of the interface:


Schematics

The trick of the trade

It all works thanks to the Z80's /WAIT pin, when an IN or an OUT instruction happens for an port below 31 the logic gates put this pin to a low sate making the Z80 wait, the Arduino notices that and can fetch the data from the computer and put it onto the 74245 buffer, then the Arduino will raise the /WAIT pin to make the Z80 resume the execution so the OUT instruction gets the data from the buffer.

The software bit on the MSX side...

My computer didn't have a disk BIOS so I had to get one, fortunately Arjen Zeilemaker had disassembled some and put the asm code in sourceforge. All I had to do was to write the DSKIO function to talk with my arduino, the code was so simple that I just used notepad and worked on the second run. I took a game cartridge and replaced the game's ROM with an 16Kb EEPROM I got from EBAY. As for writing the EEPROM I used a reader/writer I built once as a quick hack, I used for that a ATMEGA128 since it has enough pins to driver teh 28 pins you need to set in order to write or read an EEPROM.

Simple flash memory reader on the top, game cartridge on the bottom

The two white cables sticking out of the Atmega128 are the serial port, I wont tell what are the black and red ones :-)

..and on the PC side

I just used Python to read the commands coming from them MSX, the script will take the 512 bytes sector and will send it to the arduino and 1Mbit per second. The Arduino will send byte by byte to the Z80 at a similar speed.


Here is the video, sorry for the shaky hand :-) On the left you have the python script, on the right VLC media player.



Source code! :)


Ok here are the sources, sorry I didn't document the code so much, please let me know if you have any questions.
https://docs.google.com/file/d/0B4IJZPdCtzO0OGJvcnB3U0xnY1U/edit?usp=sharing

Thursday, 6 October 2011

DIY Linear actuator out of scanner parts and a drawer slider

To build this linear actuator I stripped off from a scanner the motor + gears along with the timing belt and the pulley. I bought in Brico a cheap drawer slider and screwed it all into a piece of wood.

First the video showing off what all this is about




Below you can find a pic of one end of the actuator:

IMAG0336


As you can see, I attached the stepper to the piece of wood by just using a wire, and it works great!
Also note that zigzag piece of metal that links the timing belt with the drawer rail. In the picture below you can see it in more detail

IMAG0337


The timing belt is sandwiched between two pieces of metal.

And finally below you can see the pulley at the other end, this was a tricky part, keep reading more the details!

IMAG0338


This pulley had an axis that was riveted to the chassis of the scanner, I pulled it off with my pliers and welded it into a screw using solder, I had to heat both parts for a long time before in order to get the solder to bind both parts, the picture below shows the results:

IMAG0344


And voila, its working better than I expected! Keep tuned for more and thanks for reading!

BTW greetings goes to the guys in timelab for inspiring me!

Saturday, 17 September 2011

A Pre Amp for an electric guitar

I bought an electric guitar and needed an amp, I thought is was kind of silly to buy one since I could use my computer speakers. You cannot connect the guitar to the computer amp directly since the signal coming from the guitar is too weak, you need a preamp.

I had a bunch of 741 op amps around and decided to build a preamp myself. I used a inverter amp configuration (quite a simple one) and it worked great. By cranking up the gain by a lot I get a nice heavymetal distortion.




Here is the schematic along with a link to see it running in a free java circuit simulator.





The only problem is that the preamp seems to amplify too an FM radiostation and I can hear some nice music while I play guitar....

At the beginning I thought my guitar was haunted by The Beatles and played on its own, when I hard a kind of a voice I suspected it could be receiving some sort of radio signal.. 

 You don't believe me? Check out this video! 






Gameboy Cart Using an AVR

Built a Game Boy flash cart using an AVR. Took a cartridge I bought for a few euros and replaced the ROM chip with a 32Kb RAM I took from a printer. The pinout of most RAM, ROM and EEPROM chips are almost the same, I was quite glad about this :-)

The next step was to find a processor that had many free pins to drive the 15 for the address bus and 8 for the data bus, for that then I used and AVR128.



If you look at the cartridge 'pins', you'll see a cable soldered to one of them, that is the HALT line of the Z80, controlling this pin I can freeze the Z80, this way the data and addresses buses are free and my AVR can write and read data from my RAM.



This is how the whole setup looks like once connected, the big chip is the AVR .

I can write programs in the RAM in two ways:

1) Connecting the AVR to my computer through a serial port and use a little loader to upload apps.
2) Write the app I want to upload in the AVR's flash and have it write it to the RAM when the Game Boy is turned on.

So, bottomline :-) It worked for small apps < 16Kb but it didn't work for bigger apps, so I think this post will have a second part someday, stay tuned!

Tuesday, 12 October 2010

How to get support for the Arduino oscilloscope (and Parallax),

We now have a forum, please ask your questions there!

http://groups.google.com/group/xoscillo

Thanks!

Wednesday, 29 September 2010

Arduino oscilloscope (and Parallax)

I wrote some software so you can use your computer as an oscilloscope.

In the following screen shot you can see the software acquiring data from an arduino and also from a Parallax USB oscilloscope simultaneously.




For more info, more screen shots and source code go to:

https://code.google.com/p/xoscillo/

We have a wiki with the instructions and a forum, please use them! ;-)

Wednesday, 15 September 2010

DIY Laser projector

So yes! Hello!!! This time I built a laser projector, it was built using a toy laser pointer, a pillbox, a cooler fan and an arduino microcontroller.



Check out this video if you want to see it in motion (note that its a bit dark, but towards the end I turn on the lights)




Here is how it works!


In the picture below you can see the whole setup, the heptagon is a pillbox, its sitting on top of a cooling fan so it spins very quickly. Each side of the pillbox has a mirror that reflects the laser beam onto the screen.



Because the mirrors are moving the reflected laser dot sweeps the screen from left to right, because it does it very quickly your eyes actually see an horizontal solid line, in this case you see 7 lines one on top of the other because the each mirror is at an angle.

So I would get something like this:

-------------------------------------------------
-------------------------------------------------
-------------------------------------------------
-------------------------------------------------
-------------------------------------------------
-------------------------------------------------
-------------------------------------------------

if I turn off the laser at the right time, I could get to display something like this

-- -- -------- -- -- ----- --
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
-------- -------- -- -- -- -- --
-- -- -- -- -- -- -- --
-- -- -- -- -- -- --
-- -- -------- ------- -------- ----- --


Then with a little bit of software magic you can get the text to scroll, wave, and so on.

We are not there yet!

The spinning speed of the fan is very critical, any slowdown will cause the image to wobble, that is why I put this fins on the pillbox, when they spin they pass thought an optical sensor (pretty much like the one elevators have to keep its doors open when people leave or enter the elevator) A micro controller can use this data to compute the fan speed and adjust the laser blinking to the image looks correct.

Tricky part! (warning quite geeky stuff coming up!)

So how does the micro controller know when is the first mirror coming? The fins, because I glued them myself by hand, are not really equally spaced, some are closer that the others, the micro controller notices this and uses this info to tell which one is the first mirror... for example the two fins before the first mirror are a bit closer than the others.

That's all, I hope you enjoyed!


Other Laser projectors:

http://heim.ifi.uio.no/haakoh/avr/

Sunday, 13 September 2009

poor's man CNC hot wire cutter - Updated!


This time I built a computer controlled device that will allow you to cut out shapes from styrofoam boards with great precision.

To make it more fun I tried to build the whole thing by re-purposing scrap parts I found here and there, so I used a couple of scanners, a hanger and a hot wire. The scanners I found them on the trash (officially I will deny that I pick stuff from the trash), the hanger I got it from my cleaning service and the hot wire was 3 euros.

This is the way it works, draw a shape using your favourite drawing software or download one from the internet, just make sure the file is a SVG, because that is what my system understands.

I found myself this nice eagle, which is quite a complex shape as you can see:
And this what you get:



Here is the promised video so you can see the system in action...




Here are some pictures showing details of the CNC

Saturday, 30 May 2009

Hacking a pager (part 1)

I bought this weekend a pager for 2 euros and decided to plug my scope on it to see what could I find out. The case mentions 147.250MHz, and "RTT/SMF/X205", unfortunately this didn't help much!

I plug my scope on the digital output of the receiver and I noticed a burst of serial data every 1 second exactly.



I zoomed in to see how this bursts look like and this is what I got:



BTW the blue channel is hooked to a pin that goes low every time there is serial data coming in the red channel.

The next think I noted, is that once in a while I get loooong bursts of serial data that last for 4 seconds



Any idea what protocol this could be? It doesn't look like FLEX or POGSAC...

Thanks everyone for reading, any info is welcome!

Tuesday, 31 March 2009

Logging temperature

Displaying static pictures on an LCD is quite cool (see my previous post) but it doesn't get you very far, does it?
I always wanted to build my own temperature logger and graph it in a display, so it was now or never! I had a couple of I2C temperature sensors lying around and also a serial EEPROM, so I hooked them all together, and voila voila!!



Time for details now! Sorted from fun to less fun :-)

- The data scrolls one pixel every 5 minutes, the LCD is 128 pixels wide I can display the temperature for the last 10.6 hours.

- The flat part of the graph is during the night, as you can see the thermostat is doing a great job at keeping a constant temperature!

- The non-flat part is during the day the sun enters through the windows and heats up the place. There is a small spike and that is because for while the sun hits directly the sensor.

- For the clock, I used the fact that I can drive one of the AVR's timers using an external oscillator, I used a 32.768MHz crystal this number is exactly 128*256, so you just have to set the timer's prescaler to 128 and you'll get a 8bit timer overflowing once a second. Se the timer to generate an interrupt at that point and that's it. Look at the Atmel's Butterfly source code for reference.

- Drawing the line was quite tricky, because the LCDs' framebuffer is not linear at all and also because I wanted to write up to 8 pixels with the same memory access. It was tricky but I made it, I'll probably post the code in another post.

- The rest is simple stuff, the temperature sensor is a LM75A, and the serial EEPROM is a 128Kb one.. both of them are controlled using and I2C bus, so piece of cake!

And now the full monty:


More details on demand, Thanks for reading!