Arduino Offset printer page counter

My brother’s Offset printing machine was giving him trouble counting pages. There is voltage stabilizer connected to protect the machine from voltage beyond 110V. Whenever printer shut-off due to voltage fluctuation the counter of machine goes to zero again. This situation irritates him, as remembering pages is not easy while printing 1000-2000 pages at a time.

This picture shows four 7-segment displays connected that can show maximum number of 99999 pages. Continue reading

USB to RS232 without using any line driver IC

This prototype is a total replacement of line driver IC & works very well. Used discrete components in place of line driver ICs. I’ve taken reference from Sparkfun tutorial https://www.sparkfun.com/tutorials/215

I have used USB to TTL converter (CP2102) module for interfacing with laptop. Now when I prototyped the circuit it was not working. I wondered what’s going on.

After replacing components & some tweaking I had found out that it’s the transistor who is responsible for jam. Actually every transistor has beta (current amplification factor) value which changes from transistor to transistor. So I replaced PNP transistor base resistor with a potentiometer of 10k value. Continue reading

Arduino control over serial

I hope that you are familiar with Arduino basics. This post is just to show you how to control Arduino over serial data sent through keyboard.

Open your Arduino IDE.

Start by allocating a variable name to our LED and setting it as output.

const int ledPin = 13;
void setup()
{
  pinMode(ledPin, OUTPUT);
}
void loop()
{
}

To communicate with our processing sketch you need to initialize the serial communication; this can be done by calling the ‘begin()’ method on the ‘Serial’ object. The syntax used for initializing the Serial port is:

Serial.begin(baud_rate);

Baud is a variable unit of data transmission speed, or simply 1 baud = 1 symbol per second. A baud rate of 9600 will be fine for us.

Serial.begin(9600);

Our serial port is initialized now need to check for any available data. Therefore, in our loop() function we use a simple if statement to check if there is any available data.

if(Serial.available())
{
}

If Serial.available() evaluates to true, then ‘if’ block will be executed.

We have opened up the serial port & checked for data availability over serial, now our next job is to actually use the data to command Arduino to do desired. Declare a variable of type char called inputValue and assign it to the data available in the serial buffer.

char inputValue = Serial.read();

The read() method takes the data available in the Serial buffer and stores it to inputValue variable. This statement is typed inside the ‘if’ block.

Now, if the data we receive is ‘H’ we will turn on the LED if it is ‘L’ we will turn off the LED, if it is neither ‘H’ or ‘L’ do nothing.

if(inputValue == ‘H’)
{
  digitalWrite(ledPin, HIGH);
}
else if(inputValue == ‘L’)
{
  digitalWrite(ledPin, HIGH);
}
else
{
  //  do nothing if anything other than a ‘H’ or a ‘L’
}

At the end of the loop() function add a small delay() of 10 milliseconds to avoid overloading the Arduino with data.

Source Code

const int ledPin = 13;
void setup()
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}
void loop()
{
  if (Serial.available())
  {
    char inputValue = Serial.read();
    if(inputValue == 'H')
    {
      digitalWrite(ledPin, HIGH);
    }
    else if(inputValue == 'L')
    {
      digitalWrite(ledPin, LOW);
    }
    else
    {
      // we will do nothing if the data is anything other than a ‘H’ or a ‘L’
    }
  }
  delay(10);
}

Once upload program it to your Arduino, and open the Serial Monitor. Try sending the values to Arduino like ‘H’, ‘L’ or anything else. The LED should light up every time you send an ‘H’ and should turn off when you send a ‘L’.

Getting started with Arduino + Pyhton

Learning Python opens many doors for any newbie. As codeacademy helped me realize my dream to learn Python, I want to use this knowledge to make some embedded stuff. The first think that came in my mind was Arduino. Yes, anyone who is familiar with Arduino & want to apply his/her Python skills then this post may be beneficial for them.

Hardware requirement

Arduino UNO or Arduino Atmega328 will be enough to get started.

Software requirement

Here come little tricky part. I hope Python is already installed on you system (Windows/Linux). Since python will communicate over serial there is an addition package you need to download that is called Pyserial, as the name seems obvious. Windows users can run setup directly, Linux users can too. But Linux users must be searching for command so I may ease their work following these steps:-

1. Open terminal -> Get super user access -> user password

sudo su

2. You can use any one of below two methods

pip install pyserial

or

easy_install -U pyserial

3. That’s it, you are done with installation part. Now open you Python IDE (windows user) and Linux users (terminal -> idle)

idle

4. Python shell -> file -> New window -> save as -> blinkled.py ->

Image

ImageImageImageImage

 5. These two lines will import necessary modules from library.
     Now this is tricky part, how to connect to serial port. Go to device manager (Windows) & find in ports. But for Linux users           there is a command to find out COM port to which Arduino is connected.
dmesg | grep tty

it will show COM port to which device is connected. Now you need to assign a variable in Python IDE for arduino board,             name it Arduino itself. Now you code will look like this.

Image

You should change the COM port, if it is connected to different port.
Note: Be careful with the Baud Rate. The baud rate mentioned in Python IDE should be same as the baud rate chosen for Arduino serial monitor. For example, some Sonar sensor libraries talks with Arduino on 115200 baud rate (Better to take care of it rather than scratch your head for hour when things doesn’t work).
6.  Now finally if you are familiar with Python then you can get whole idea of how code is written & how it is working. Final coding looks like this-
Screenshot from 2013-10-22 13:32:32
7. Finally run the program from    ( run -> run module) or you can press F5 that will prompt to save. Save & view the Python         shell. It will look like this-
Image
Troubleshooting
But wait, what is going on their? The LED (Pin 13) is not blinking what is going on? Python code seems to be working fine but what is the matter with Arduino board?
Well, well, well here is the matter with the stuff. Python is sending some string ‘H’ and ‘L’ over serial pin but Arduino is not able to understand what to do with these command. Perhaps I need to program Arduino first with instructions that tell it to make LED high when it receive ‘H’ over serial & make LED low for ‘L’ .  Follow my other post to do that. After uploading the program, run your saved Python program & all things will work fine. DONE!!!!!
Source Code
You can directly use these codes into your Python IDE.

import serial
import time
Arduino = serial.Serial(‘/dev/ttyACM0’, 9600)
time.sleep(2) # waiting the initialization…
print(“initialising”)
while True:
Arduino.write(‘H’) # turns LED ON
print(“LED ON”)
time.sleep(2) # waits for 2 secondArduino.write(‘L’) # turns LED OFF
print(“LED OFF”)
time.sleep(2) # waits for 1 s
Arduino.close() #say goodbye to Arduino