Category Archives: Electronics

Pi Maker Workshop and RasPi resources

One of the most interesting things I did all summer was a workshop called Pi Maker that I conducted as a launch event for a new MakerSpace in Noida (close to Delhi, India). Helping a group of people visualize the endless possibilities in the world of DIY electronics by using the Raspberry Pi as a medium, was in itself, quite rewarding. 🙂

The main content for the workshop was provided by Inventrom robotics initially, which I modified to include all that I’d discovered and learnt in these past few years of working with the Pi. I also had a lot of support from RobotechLabs in Delhi to help setup this entire event.

I’ve uploaded the material on SlideShare and anybody looking to get started with the Pi from scratch (no electronics/programming past experience) or maybe on the hunt for some inspiration can have a look at them 🙂 Feel free to share and use but please don’t modify the slides in any manner that removes the existing watermarks.

Here’s a link to the first presentation in a set of 6:

http://www.slideshare.net/mayankjoneja/1intro-37584027

Head over to these websites and check out the cool work they’ve been doing too!

http://raspberrypiworkshop.inventrom.com/
http://inventrom.wordpress.com/
http://www.robotechlabs.com/

https://www.facebook.com/makerspacenoida
https://www.facebook.com/inventrom

In order to draw in more participants, here’s a sort of promotional video that I’d cooked up :

I’d promised to put up the relevant explanation for this Intruder Alert system, and here’s my shot at it.
Here’s what happens when a person tries to enter my room:

  1. A PIR sensor detects a human presence which sends a signal to a GPIO pin on the Raspberry Pi
  2. The Pi communicates with the Arduino via serial and also plays a wailing siren from omxplayer
  3. The Arduino Uno, on receiving data from the Pi through a USB cable, switches on the christmas lights on the floor through a relay board.
  4. The Pi sends me an e-mail using ssmtp saying that somebody tried to enter my room
  5. An IR LED connected to the Raspberry Pi is used to trigger off my Nikon camera mounted on a tripod using LIRC

    Here’s a look at the code:

code

and here’s a peek at the hardware layout 🙂
Layout

This is the basic PIR sensor code I’d implemented first before setting up the Intruder alert system:


import RPi.GPIO as GPIO
from time import sleep
# from subprocess import call
import os

GPIO.setmode(GPIO.BOARD)

GPIO.setup(7,GPIO.OUT)
GPIO.setup(11,GPIO.IN)

GPIO.output(7,True)

while True:
	sleep(1)
	if GPIO.input(11) == True:
		os.system('omxplayer /home/pi/Projects/PIR/hey.mp3')

I’d hoped to get some individuals hooked on to this amazing and rewarding world of magic through this workshop and I hope that the slides I’ve uploaded help me in spreading this know-how to other far-off places thorough the internet.

Just to show off the MakerSpace and give a glimpse into the 2 day workshop:

Advertisements

IR Remote for Nikon Camera using the Raspberry Pi (LIRC)

I finally came around to trying out LIRC on the Raspberry Pi to use it to trigger my Nikon D5100. 😀

I haven’t fully utilized the capabilities provided by it yet, but I’ve managed to get it up and running quite easily thanks to a lot of great posts and troubleshooting guides on some blogs and the Raspberry Pi forum.

I mainly followed these links:

http://www.instructables.com/id/Raspberry-Pi-Universal-Remote/

http://alexba.in/blog/2013/01/06/setting-up-lirc-on-the-raspberrypi/

To make a very simple remote using the Raspberry Pi, all you have to do is follow the steps given on either of these links.

Since I didn’t really have the physical Nikon ML-L3 universal remote which I wanted to emulate, I followed the steps given on these links after which:

1. I upgraded the firmware:

sudo apt-get update
sudo apt-get upgrade
sudo rpi-update

2. Got the Nikon ML-L3 lircd.conf file:

http://lirc.sourceforge.net/remotes/nikon/ML-L3

and replaced the contents of

/etc/lirc/lircd.conf

3. Restarted the lirc daemon:

sudo /etc/init.d/lirc restart

4. Checked if the remote was configured correctly:

irsend LIST Nikon2 "" 

This should show a list of the commands offered by the remote for triggering the shutter.

5. Tested the shutter command:

irsend SEND_ONCE Nikon2 shutter

6. Once that worked properly, (after a silent fist-pump) I decided to write a small python script that I can use for Timelapse shoots:

#Created: 09-07-2014 AM 02:38 
#Author: Mayank Joneja
#https://botmayank.wordpress.com
#Timelapse code for Nikon Cameras using the Raspberry Pi (LIRC)
#IR LED on GPIO 22 , usage:
#sudo python NikonCamera.py [no. of shots] [delay in seconds]

from time import sleep
import subprocess
import sys

if(len(sys.argv)<3):
	print "usage: 'sudo python NikonCamera.py [no. of shots] [delay in seconds]'"

else:
	shots = int(sys.argv[1])
	delay = float(sys.argv[2])

	for i in range (1,shots+1):
		subprocess.call('irsend SEND_ONCE Nikon2 shutter',shell = True)
		sleep(delay)

I’m quite happy with this setup as of now, but I plan to hookup a TSOP and make a small setup for recording and transmitting IR signals with the Pi. I guess I’ll then have a simple Flask based web-app for such an IR blaster.

I haven’t really tried out the range of the setup yet but I think in case of any issues I’ll simply amplify the signal with an NPN transistor like a BC547 and add another LED in parallel for better coverage angle. I’ll post any updates on this project as and when I get to them.

P.S.:I hope to click a nice timelapse sequence with this camera ASAP and upload that too. 🙂

DIY Portable Speaker Amplifier using LM386

For one of my first audio circuits, I decided to make a simple amplifier circuit based on the LM386 IC to power an 8 Ohm 0.5 W Speaker. I started off based on the schematic provided in this instructable:

http://www.instructables.com/id/Portable-Speaker-1/?ALLSTEPS

But once I was done with it, I wasn’t really impressed with the audio quality. The audio would start to crackle really soon and there was very little clarity. As it turns out, all I had to do was add a 0.047 uF capacitor at the output and a 0.01uF capacitor  at the input as decoupling capacitors to get a remarkable upgrade. The more common schematic for this application was available at:
http://www.instructables.com/id/Make-a-Simple-Audio-Amplifier/

Oh and for anybody interested in making this project, do check out this awesome detailed post and video by Hackaday:
http://hackaday.com/2011/05/01/lm386-altoids-tin-amp/

and the original hackaweek post:
http://hackaweek.com/hacks/?p=131

So effectively the schematic I used resembles:

(http://hackaweek.com/hacks/wp-content/uploads/2011/04/LM386ampschematicfinal1.jpg)

In order to test my amp, I even wanted to try using an Arduino to drive this speaker instead of the usual annoying Piezo Buzzer I’d used so far for audio output. I used the sample code from the tutorial dealing with the tone() function in Arduino:
http://arduino.cc/en/Tutorial/tone

Here are some pics of my implementation:

And here’s how it sounds:

Future Plans:
1. Adding a bass boost as mentioned in the reference post
2. Trying out a guitar input and output to headphones
3. Putting it in a case

Running the Nokia 6610 LCD with a Raspberry Pi

A while back, I’d bought the Nokia 6610 LCD thinking of it as a nice cheap display to incorporate into certain projects.

http://www.onlinetps.com/shop/index.php?main_page=product_info&cPath=9_41&products_id=776

When I finally got around to using it, I thought of looking for instructables/references on interfacing it with the RasPi, but all I found was:

https://www.sparkfun.com/tutorial/Nokia%206100%20LCD%20Display%20Driver.pdf

and

http://www.instructables.com/id/How-To-Use-a-Nokia-Color-LCD/

and slowly learnt that this particular display has been quite a challenge for the online community for a while now. I did find very nice posts about how to interface it with other platforms though:
Arduino:
http://playground.arduino.cc/Code/LCDPCF8833

AVR:
http://thomaspfeifer.net/nokia_6100_display_en.htm

But after a lot of hunting, once I started looking for projects based on the LCD’s drivers, I finally came across a github project:

https://github.com/engpedrorafael/pcf8833

I really felt a rush of gratitude towards him once I found this because the task of porting the entire C library to be used with the Raspberry Pi through Wiring Pi seemed too daunting to me. Or atleast something I’d be too lazy to do to run a simple colour LCD 😛

All the steps for running the LCD are there on his git page. In short,
1.Make the connections:

(LCD connections)

2. Get his code
3. Run it and test, convert images to the relevant dimensions (132×132 pixels) and file format, and use the python modules he’s created.

I just hope this post helps somebody else find this particular implementation much sooner that it took me considering how easy things became once I found this. Major props to Pedro. 🙂

In terms of connections, I ended up using a 330 Ohm resistor between 12V and the LED+ pin to make the display bright enough, I tried to use the 7806 but IMHO the display wasn’t really readable.

Here’s my setup:

P.S.: In case anybody’s having issues running the D-Link DWA 132 N300 Wi-Fi Dongle with the Pi, check out:

https://xneosis.wordpress.com/category/linux/raspberry-pi-linux/

Works like a charm and the dongle is one of the most reliable ones I’ve used.

P.P.S.: If you want to make your own bench power supply and haven’t seen this yet, check out my post:

https://botmayank.wordpress.com/2014/06/24/diy-bench-power-supply/

DIY Bench Power Supply

For any electronics hobbyist, one of the most crucial tools while testing/prototyping circuits on a breadboard/perfboard is a good standard power supply. But buying a typical bench power supply might not be an option for everyone.

One of the easiest (and perhaps the most useful) hardware hacks I’ve ever done is to re-use a really old PC CPU’s ATX power supply as my own bench power supply. Earlier I used to keep leeching 5V or 3.3V DC off of Arduino Uno boards powered through DC 9 V Adapters and I’d always have to use DC jack to molex or other such types of connectors in conjunction with a plethora of DC adapters to power my breadboard prototypes.

Now, I can easily use this setup to have easy access to 3.3V, 5V and 12V each capable of sourcing 3 A of current too! 🙂
The best part is, there’s really not much that you need to do to get it up and running!

Here’s what an ATX power supply looks like:
http://www.ebay.in/itm/like/intex-450w-smps-atx-power-supply-sata-connectors-/271505046206?pt=in_computer_components

You can get one for around INR 800 (13 USD) easily from a local computer hardware store or online.

Here’s the pinout of the connectors on such an ATX supply:

atx-psu-pinouts
(http://www.helpwithpcs.com/courses/power-supply/atx-psu-pinouts.gif)

As you can see on the main ATX 20 pin connector, most of the standard operating voltages that we need for any electronics projects are right there! The only hitch is, you can’t just plug it in, flip the switch on the back, and make it run.

Remember how your PC CPU powers up? You have to push the power button right? The connection responsible for the powering up is the PS_ON pin shown there. For our purposes, we simply have to short that with GND to get the power supply up and running. So you could simply snip, strip and twist them together, or as I’ve done in my case, connect it to a small slider switch.

DSC_0675     DSC_0678

As for the other supply voltages, I’ve stripped them and connected the wires into this small “distribution circuit” which is essentially just screw terminals for the 3.3V, 12V, 5V, GND wires along with rows of male headers for the same along with a “Power On” green LED and the slider switch. You could even use the ATX 20 pin connector as is, but the molex connector on that has sockets that are larger than the usual breadboard hole sized male headers and that is why I went in for such a setup. ….and we’re done!

I found plenty of instructables online for setting this up and I thought that I could just help add to the list of resources out there so that more people starting off into DIY electronics or budding “Makers” could maybe have some easy access to these common voltages with very little effort, time and/or money.

TL;DR:

Step1: Get the ATX power supply
Step2: Short the Green wire with any one of the black wires on the 20 pin header
Step3: Solder a small perfboard distribution setup if you want
Step4: Plug it in, and DONE! Hookup your breadboard circuit and enjoy!

P.S. Be safe while dealing with the power supply and handling AC voltage and do leave room for the cooling fan at the back of the ATX power supply box

Some more pictures of my setup :

I even hooked up a push button switch and 2 wires to a small DC motor that I can drive with this supply. I intend to fix standard PCB Drill bits with it by gluing the chuck that I can take out from a normal hand press PCB drill in order to have a neat automatic PCB Drill for any prototype PCB’s I make at home with the toner transfer method. I’ll post that as soon as I’m done with it.
Cheers!

Re-programmable IR Camera Remote for Sony NEX-5

I’ve been putting off this post for quite a while because I wanted to do much more and then share this one particular project I’ve invested a lot of time and effort in. Instead I thought I’d share my progress till now.
( I have a working prototype by the way, I just wanted to modify it a lot more, and make the schematics etc properly.)
This post happens to be a lot like a general informal blog post because I plan to make a detailed instructable some time later with all the involved stages and iterations for the remote.

The ultra-short version? It’s an IR remote for a Sony NEX 5.

Video demo:
http://www.facebook.com/photo.php?v=10151647956756594&l=8701802626708426185

The slightly detailed one?

It has 2 modes; Manual:Whenever you press the button it clicks, Auto: It clicks every few seconds (the duration can be set), intention behind this mode was trying to do time-lapse photography.

It also has Tx and Rx headers for easily re-programming the Atmega 328P to play with the code and, for instance, include Canon/Nikon codes, or use the remote platform to control other devices like TVs, A/Cs etc.

And now I commence with the full plunge.

I really wanted to try timelapse photography with my camera, Sony NEX, but unfortunately there wasn’t any proper software that I could find at the time, or any way of doing proper tethered shooting with it. I was too scared to mess with the firmware, and I wanted to make my own remote for the camera as well. So instead of buying an intervalometer/remote, I started setting up an Arduino based circuit.

Some specifics of the circuit:

-Arduino bootloader on the Atmega 328P which I made the remote around, working on 8MHz internal clock.
-Hardware debouncing using schmitt triggered inverters and RC circuits for the Push-buttons
-Runs on a 9V battery, used a LM7805 get it down to 5V to power the board.
-BJT based amplifier circuit to maximize the range of the remote (4.5 meters as of now)
-Onboard 10k potentiometer to set the delay for the timelapse mode, as of now calibrated to give min. 10s to max 45s delay between clicks.

Future plans:

-Shifting it to the AtTiny2313 to avoid wastage of pins and to make it smaller
-Running it on 3V3 logic so that I could use a lighter battery
-Modifying the code to incorporate Sebastian Setz’s library
-Actually implementing the time-lapse functionality properly
-Adding a batter indicator as per Lucky Larry’s project.

http://luckylarry.co.uk/arduino-projects/arduino-ir-remote-intervalometer-for-nikon-d80-that-means-timelapse-photography-yarrr/

http://sebastian.setz.name/arduino/my-libraries/multi-camera-ir-control/

There and back again:

The entire exercise turned out to be a great learning process. I started off with the basics of IR remotes, IR protocols, Sony, NEC, and the Ken Shirriff library for IR control for Arduino. I checked out the Adafruit tutorials for making a canon/nikon camera remote. I struggled a lot while looking for the exact click code for my camera, but finally stumbled upon Marc Lane’s blog:

http://www.l8ter.com/?p=333

Once I was able to click using a normal Arduino Uno and an IR Led connected to it, I wanted to make a compact version with custom button positions,a hardware debouncing circuit for them,  a range booster and have the Atmega 328P run the Arduino bootloader.

I laid out the design on a breadboard and followed :http://arduino.cc/en/Tutorial/ArduinoToBreadboard

Once I was done with the basic setup, I started to optimize my code by using interrupts. I wasn’t happy with the multiple presses the “mode button” was registering when I pressed it. I then found Jeremy Blum’s excellent lesson for hardware debouncing.

http://www.jeremyblum.com/2011/03/07/arduino-tutorial-10-interrupts-and-hardware-debouncing/

After a lot of frustrating debugging, my final breadboard setup looked something like this:

Remote Fritzing Schematic
The remote during various stages of development:

This slideshow requires JavaScript.

The code as of now is mainly Lucky Larry’s code, modified to use interrupts and to work as per my hardware setup and use the Sony NEX click IR Code instead of the Nikon one. Here’s the original code again:

http://luckylarry.co.uk/arduino-projects/arduino-ir-remote-intervalometer-for-nikon-d80-that-means-timelapse-photography-yarrr/

And the one I’m using on my setup:


/* Mayank Joneja;
Implementation of Lucky Larry's code for a custom IR remote for the Sony NEX 5 */

/*
LUCKYLARRY.CO.UK - IR Remote control for Nikon using Arduino
Mimics the infrared signal to trigger the remote for any Nikon camera
which can use the ML-L1 and ML-L3 remotes. Can be used as an intervalometer
for time lapse photography.
The IR sequence I used is originally taken from: http://www.bigmike.it/ircontrol/
You should be able to use my pulse methods to alter to suit other cameras/ hardware.
micros() is an Arduino function that calls the time in Microseconds since your program
first ran. Arduino doesn't reliably work with microseconds so we work our timings by
taking the current reading and then adding our delay on to the end of it rather than rely
on the in built timer.
*/

int pinIRLED = 12; // assign the Infrared emitter/ diode to pin 12
int LEDgreen = 13; // use onboard led for battery status
int batteryIn = 0; // set pin to get power data from
int batLevel = 0; // variable to get details on battery power level from analog input
int lowPower = 0; //count to keep track of lowpower state
long int td; //delay between shots
volatile boolean mode = false;

int modeButton = 0; // Mode button wired to INT0
int clickButton = 8;// Click button wired to digital pin 8

int modeLed = 7; //An indicator LED to show the mode
int clickLed = 13; //An indicator LED for the clicking in mode2

void setup() {
pinMode(pinIRLED, OUTPUT);
pinMode(modeLed,OUTPUT);
pinMode(A0,INPUT); // set the pin as an output
attachInterrupt(modeButton, modeSwitch, RISING);
}

void modeSwitch()
{
mode =!mode;
digitalWrite(modeLed,mode);
return;
}

// sets the pulse of the IR signal.
void pulseON(int pulseTime) {
unsigned long endPulse = micros() + pulseTime; // create the microseconds to pulse for
while( micros() &lt; endPulse) {
digitalWrite(pinIRLED, HIGH); // turn IR on
delayMicroseconds(13); // half the clock cycle for 38Khz - e.g. the 'on' part of our wave
digitalWrite(pinIRLED, LOW); // turn IR off
delayMicroseconds(13); // delay for the other half of the cycle to generate wave/ oscillation
}
}
void pulseOFF(unsigned long startDelay) {
unsigned long endDelay = micros() + startDelay; // create the microseconds to delay for
while(micros() &lt; endDelay);
}
void takePicture() {
for (int i=0; i &lt; 2; i++) {
pulseON(2336);
pulseOFF(646);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(646);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(572);
pulseOFF(646);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(11008);
pulseON(2336);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(646);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(572);
pulseOFF(646);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(11008);
pulseON(2336);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(646);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1168);
pulseOFF(621);
pulseON(1093);
pulseOFF(696);
pulseON(572);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(572);
pulseOFF(621);
pulseON(572);
pulseOFF(1218);
pulseON(497);
pulseOFF(1292);
pulseON(422);
pulseOFF(1367);
pulseON(373);
pulseOFF(11803);
pulseON(298);
pulseOFF(2659);
pulseON(199);
pulseOFF(1590);
pulseON(174);
pulseOFF(1019);
pulseON(174);
pulseOFF(1615);
pulseON(174);
pulseOFF(1615);
pulseON(149);
pulseOFF(1044);
pulseON(149);
pulseOFF(1640);
pulseON(124);
pulseOFF(1093);
pulseON(149);
pulseOFF(1044);
pulseON(124);
pulseOFF(1665);
pulseON(124);
pulseOFF(1068);
pulseON(124);
pulseOFF(1665);
pulseON(99);
pulseOFF(1690);
pulseON(99);
pulseOFF(1690);
pulseON(99);
pulseOFF(1093);
pulseON(99);
pulseOFF(1118);
pulseON(99);
pulseOFF(1093);
pulseON(99);
pulseOFF(1690);
pulseON(99);
pulseOFF(1690);
pulseON(75);
pulseOFF(1715);
pulseON(75);
pulseOFF(12101);
pulseON(149);
pulseOFF(2833);
pulseON(75);
pulseOFF(1715);
pulseON(75);
pulseOFF(1118);
pulseON(75);
pulseOFF(1715);
pulseON(75);
pulseOFF(1715);
pulseON(75);
pulseOFF(1118);
pulseON(75);
pulseOFF(1715);
pulseON(75);
pulseOFF(1118);
pulseON(99);
pulseOFF(1093);
pulseON(99);
pulseOFF(1690);
pulseON(99);
pulseOFF(1093);
pulseON(99);
pulseOFF(1690);
pulseON(99);
pulseOFF(1690);
pulseON(99);
pulseOFF(1690);
pulseON(99);
pulseOFF(1093);
pulseON(99);
pulseOFF(1118);
pulseON(99);
pulseOFF(1093);
pulseON(99);
pulseOFF(1690);
pulseON(99);
pulseOFF(1690);
pulseON(99);
pulseOFF(1690);
pulseON(99);
pulseOFF(646);
} // loop the signal twice.
}
void batterytestdelay(unsigned long delaytime){ // Function to check battery level and flash the led if its low battery
long tempdelay = 0;
while(delaytime &gt; tempdelay){
delay(100);
tempdelay = tempdelay + 100;
batLevel = analogRead(batteryIn);
if (batLevel &lt; 720){
lowPower++;
}
if (lowPower &gt; 100){
lowPower = 0;
}
if (lowPower &lt; 50){
digitalWrite(LEDgreen, LOW);
}
else{
digitalWrite(LEDgreen, HIGH);
}
}
}

void loop() {

if(mode==false) // mode1
{
while(mode == false) // as long as the device is in mode1 (will switch modes if interrupted by mode switch being pressed
{
td=(analogRead(A0)*25);
takePicture();
delay(td);
}
}
if ((digitalRead(clickButton) == HIGH) &amp;&amp; (mode == true)) //Click is pressed and device is in mode2
{
digitalWrite(clickLed,HIGH); //indicator LED
delay(100);
takePicture();
digitalWrite(clickLed,LOW);
}
}

I plan on making a better attempt at cataloging this project and implementing all the things I mentioned in the beginning. I hope I can then end up with a better post with all the rough edges, like the code formatting, the actual PCB Design, etc taken care of. I also plan on making my own PCB for the next prototype instead of hand soldering it the way I did with this one.

In case you read this till the end, thanks a lot for your time!
I hope this post can be of some level of assistance in case you’re planning on making something similar. Do check out all the links I mentioned 🙂