Showing posts with label arduino. Show all posts
Showing posts with label arduino. Show all posts

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.

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 :)



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