Friday, March 27, 2015

[SOLVED] avrdude: ser_open(): can't set com-state for "\\.\COM6"

CAUSE:

once upon a time when i was noob in Arduino i tried to connect my Arduino and computer with the help of Processing and tried to change the color of the display screen with the help of potentiometer.
In this process something went wrong and the display on the screen started to flicker. Ignoring that i tried again at that time my led on Rx pin started glowing continuously and then kept quite after sometime i was able to connect the Arduino but couldn't write to it. Every time i tried to write to it,it gave the same error with  msg (avrdude: ser_open(): can't set com-state for "\\.\COM6").

Noticing that i tried to solve it in many ways:
1. Pressing reset with different time intervals
2. Connecting to different ports
3. Connecting to different computers
4. Checking connectivity

But nothing worked so i thought that i have shorted the board and have to buy one. Then i thought if my Arduino was shorted then it shouldn't be able to be connected my computer as the controller or some circuit got shorted but it was connecting so  then i got the idea how to resolve it.

SOLVED:

  1. Reset the Arduino by pressing reset button.
  2. Uninstall all the Arduino compiler files including the drivers from the device manager of your computer. PLZ note the com port of Arduino in the device manager.
  3. Connect and check whether the Arduino is shown in device manager if shown then uninstall it manually
  4. Re install the Arduino compiler and hook up Arduino to it.
  5. Re install all the Drivers
  6. At this time you will see that the com port had changed if it didnt then change it manually from device manager 
  7. Cross your fingers and write the blink code to.
  8. Now this should work properly

ANALYSIS:

what i understood is that the msg goes something like this the device cant access the files relate to Arduino(avrxxxx)which is located in the com(xxx) port and the port status cant be updated with the current new values so resolve it manually.

Note: this should work in most cases including varies other errors which prevent from writing to the Arduino board.

Thursday, March 26, 2015

INTRODUCTION TO I2C PROTOCOL

I2C: Stands for inter-integrated circuit. It is a protocol intended to allow multiple "slave" digital integrated circuits (“chips”) to communicate with one or more “master” chips.It is only intended for short distance communications within a single device.It uses only two active signal lines (serial Data (SDA) & serial clock (SCL) ) which are bidirectional  to exchange information b/w various devices.
The protocol defines:
-7 bits slave addresses: each device connected to the bus has got such a unique address 
- data divided into into 8-bit + 1 (ACK/NACK)
-a few control bits for controlling the communication start, end, direction and for an acknowledgment mechanism.
Data rate has to be chosen depending on the ic but for most it varies b/w 100~400kbps.

HOW I2C PROTOCOL WORKS:

At any given time the device that is transmitting the data acts as the master while rest act as slaves.So first the master issues a start condition. This acts as an 'attention' signal to all the connected devices and all will wait for the incoming data. Then the master sends the Address of the device it wants to access, along with an write or read command.Now all the ic's will compare their address with the incoming address and if it matches they produce a acknowledge signal. If it doesn't match they wait for the stop condition so as to take the bus.
Once the master receivers the acknowledge, it can start transmitting or receiving DATA with the help of R/W. After the operation it sends a stop condition releasing the bus.
I2C specifies states that data may only change on the SDA line if the SCL clock signal is at low level.
Details (2) on I2C protocol

I2C at the Hardware Level

Signals

Each I2C bus consists of two signals: SCL and SDA. SCL is the clock signal, and SDA is the data signal. The clock signal is always generated by the current bus master; some slave devices may force the clock low at times to delay the master sending more data (or to require more time to prepare data before the master attempts to clock it out). This is called “clock stretching” and is described on the protocol page.
Unlike UART or SPI connections, the I2C bus drivers are “open drain”, meaning that they can pull the corresponding signal line low, but cannot drive it high. Thus, there can be no bus contention where one device is trying to drive the line high while another tries to pull it low, eliminating the potential for damage to the drivers or excessive power dissipation in the system. Each signal line has a pull-up resistor on it, to restore the signal to high when no device is asserting it low.
Equivalent internal circuit diagram of an I2C system.
Notice the two pull-up resistors on the two communication lines.
Resistor selection varies with devices on the bus, but a good rule of thumb is to start with 4.7k and adjust down if necessary. I2C is a fairly robust protocol, and can be used with short runs of wire (2-3m). For long runs, or systems with lots of devices, smaller resistors are better.

Signal Levels

Since the devices on the bus don’t actually drive the signals high, I2C allows for some flexibility in connecting devices with different I/O voltages. In general, in a system where one device is at a higher voltage than another, it may be possible to connect the two devices via I2C without any level shifting circuitry in between them. The trick is to connect the pull-up resistors to the lower of the two voltages. This only works in some cases, where the lower of the two system voltages exceeds the high-level input voltage of the the higher voltage system–for example, a 5V Arduino and a 3.3V accelerometer.

Protocol

Communication via I2C is more complex than with a UART or SPI solution. The signalling must adhere to a certain protocol for the devices on the bus to recognize it as valid I2C communications. Fortunately, most devices take care of all the fiddly details for you, allowing you to concentrate on the data you wish to exchange.

Basics

Standard 7-bit address transfer message.








Messages are broken up into two types of frame: an address frame, where the master indicates the slave to which the message is being sent, and one or more data frames, which are 8-bit data messages passed from master to slave or vice versa. Data is placed on the SDA line after SCL goes low, and is sampled after the SCL line goes high. The time between clock edge and data read/write is defined by the devices on the bus and will vary from chip to chip.

Start Condition

To initiate the address frame, the master device leaves SCL high and pulls SDA low. This puts all slave devices on notice that a transmission is about to start. If two master devices wish to take ownership of the bus at one time, whichever device pulls SDA low first wins the race and gains control of the bus. It is possible to issue repeated starts, initiating a new communication sequence without relinquishing control of the bus to other masters; we’ll talk about that later.

Address Frame

The address frame is always first in any new communication sequence. For a 7-bit address, the address is clocked out most significant bit (MSB) first, followed by a R/W bit indicating whether this is a read (1) or write (0) operation.
The 9th bit of the frame is the NACK/ACK bit. This is the case for all frames (data or address). Once the first 8 bits of the frame are sent, the receiving device is given control over SDA. If the receiving device does not pull the SDA line low before the 9th clock pulse, it can be inferred that the receiving device either did not receive the data or did not know how to parse the message. In that case, the exchange halts, and it’s up to the master of the system to decide how to proceed.

Data Frames

After the address frame has been sent, data can begin being transmitted. The master will simply continue generating clock pulses at a regular interval, and the data will be placed on SDA by either the master or the slave, depending on whether the R/W bit indicated a read or write operation. The number of data frames is arbitrary, and most slave devices will auto-increment the internal register, meaning that subsequent reads or writes will come from the next register in line.

Stop condition

Once all the data frames have been sent, the master will generate a stop condition. Stop conditions are defined by a 0->1 (low to high) transition on SDA after a 0->1 transition on SCL, with SCL remaining high. During normal data writing operation, the value on SDA should not change when SCL is high, to avoid false stop conditions.

Advanced Protocol Topics

10-bit Addresses

10-bit address frames example.
In a 10-bit addressing system, two frames are required to transmit the slave address. The first frame will consist of the code b11110xyz, where ‘x’ is the MSB of the slave address, y is bit 8 of the slave address, and z is the read/write bit as described above. The first frame’s ACK bit will be asserted by all slaves which match the first two bits of the address. As with a normal 7-bit transfer, another transfer begins immediately, and this transfer contains bits 7:0 of the address. At this point, the addressed slave should respond with an ACK bit. If it doesn’t, the failure mode is the same as a 7-bit system.
Note that 10-bit address devices can coexist with 7-bit address devices, since the leading ‘11110’ part of the address is not a part of any valid 7-bit addresses.

Repeated Start Conditions

A repeated start condition.
Sometimes, it is important that a master device be allowed to exchange several messages in one go, without allowing other master devices on the bus to interfere. For this reason, the repeated start condition has been defined.
To perform a repeated start, SDA is allowed to go high while SCL is low, SCL is allowed to go high, and then SDA is brought low again while SCL is high. Because there was no stop condition on the bus, the previous communication wasn’t truly completed and the current master maintains control of the bus.
At this point, the next message can begin transmission. The syntax of this new message is the same as any other message–an address frame followed by data frames. Any number of repeated starts is allowed, and the master will maintain control of the bus until it issues a stop condition.

Clock stretching

A slave using clock stretching to delay the next data frame.
At times, the master’s data rate will exceed the slave’s ability to provide that data. This can be because the data isn’t ready yet (for instance, the slave hasn’t completed an analog-to-digital conversion yet) or because a previous operation hasn’t yet completed (say, an EEPROM which hasn’t completed writing to non-volatile memory yet and needs to finish that before it can service other requests).
In this case, some slave devices will execute what is referred to as “clock stretching”. Nominally, all clocking is driven by the master device–slaves simply put data on the bus or take data off the bus in response to the master’s clock pulses. At any point in the data transfer process, an addressed slave can hold the SCL line low after the master releases it. The master is required to refrain from additional clock pulses or data transfer until such time as the slave releases the SCL line.

ALSO CHECK OUT ARDUINO AND I2C TO KNOW HOW TO USE I2C COMMUNICATION 
Reference:
 1. http://www.byteparadigm.com/applications/introduction-to-i2c-and-spi-protocols/
 2. https://learn.sparkfun.com/tutorials/i2c
 3. http://www.uchobby.com/index.php/2008/09/16/introduction-to-i2c/
 4. https://courses.cs.washington.edu/courses/cse466/01au/Lecture/i2c.pdf
 5. http://i2c.info/
 6. http://www.embedded.com/electronics-blogs/beginner-s-corner/4023816/Introduction-to-I2C

Friday, March 20, 2015

ARDUINO UNO















This article is not revised yet so there may be errors and content missing. If you find any errors in this artice plz leave a comment with the correct answer to the errors also if you like some content to be added also plz leave a comment with the content.
Note- content should be related to it only.

OVERVIEW:

The Arduino UNO is a microcontroller board based on ATmega328. 
  • 14 digital input/output pins of which 6 can be used as PWM outputs.
  • 6 analog inputs.
  • 16 MHz ceramic resonator
  • USB connection
  • power jack
  • ICSP header
  • Reset button
Power to the board can be achieved from computers USB or by AC-to-DC adapter or battery.

1.0 pinout: added SDA and SCL pins that are near to the AREF pin and two other new pins placed near to the RESET pin, the IOREF that allow the shields to adapt to the voltage provided from the board. In future, shields will be compatible with both the board that uses the AVR, which operates with 5V and with the Arduino Due that operates with 3.3V. The second one is a not connected pin, that is reserved for future purposes


  • IOREF-
  • AREF- used to provide reference to A/D converter. 
  • RESET-  Used to reset the device that are connected to it or itself
  • 3.3V- Power output of 3.3v which can be used to power other devices mainly Arduino Due.
  • 5V- Power output of 5v.
  • GND- ground
  • Vin-Connect a 5v battery and get your board running i.e power arduino with this pin.
  • A0~A5- Analog pins normally used to connect analog inputs/outputs they have a A/D converter under the hood.
  • D0~D13- Digital pins
  • D0- Rx used for receiving data serially
  • D1-Tx used for transmitting data serially
  • D2- Interrupt 0 external interrupt 
  • D3- Interrupt 1
  • D(3,5,7,9,10,11) pwm pins (pulse width pins)

ARDUINO SYNTAX, INSTRUCTIONS AND CONSTANTS AT A GLANCE(UPDATE)

INSTRUCTIONS:

The instructions are case sensitive in case of compiler (Arduino 1.6.0) so use of upper case or lower case should be done properly.

 1.pinMode(pinname/pin no,direction);
this inst is used to specify the direction of the data flow
ex-1: pinMode(12,output);
This is used to declare pin no 12 as output.
ex-2: pinMode(13,input);
This is used to declare pin no 13 as input.

 2. digitalWrite(pinname/pin no,value/state); 
This instruction is used to write value to digital pins i.e (1~14 pins)
ex-1: digitalWrite(12,HIGH);
EX-2: int pinning=12
       digitalWrite(pinning,HIGH);
Both produce same output

 3. digitalRead(pinname/pin no,value/state);
This inst is used to read value from the digital pin.
ex-1: digitalRead(12);
ex-2:digitalRead(pinning);

4. analogRead(pinname/pin no,value/state);
This inst is used to read analog values from the analog pin.Its resolution is 1024 bits.
ex-1: analogRead(12);
ex-2: analogRead(pinner);

5. analogWrite(pinname/pin no,value/state);
This inst is used to write analog values to analog pin.Its resolution is 256 bits.

CONSTANTS:

1. HIGH: digital one
2. LOW: digital zero
3. INPUT: inward flow of data used at the time of pinMode.
4.OUTPUT:outward flow of data used at the time of pinMode. 

GETTING STARTED (ARDUINO UNO)

REQUIREMENTS:

  1. Arduino UNO
  2. USB cable 
  3. Download the compiler (environment) from Arduino environment and install it
STEPS TO INSTALL UNO:

  1. Connect the board to the computer using the cable. 
  2. The green power (labeled PWR) should go on.this is a indication that the board is working
  3. Next you need to install drivers.
  4. Open "DEVICE MANAGER" of your computer.
  5. Look under "OTHER DEVICES" for "UNKNOWN DEVICES".
  6. Click on "UNKNOWN DEVICES" and click update driver software.
  7. Next choose "BROWSE MY COMPUTER FOR DRIVER SOFTWARE" option.
  8. Finally navigate to and select the driver file named "arduino.inf",located in the "Drivers" folder of the Arduino Software download. If you cant find the file simple choose the "driver folder" and press OK.
  9. Now your computer will update itself.
STEPS TO SET COMPILER AND RUNNING FIRST TIME CODES:
  1. Open compiler (arduino.exe) while the board is connected 
  2. At the top you will find a option called tools.
  3. Open tools> board > UNO (your model if its mega select mega and so on).
  4. Again open tools> serial Port > select com(for me its com6) check yours from (device manager> PORTS(COM & LTP) >ARDUINO UNO.

  • NOW OPEN file>examples>1.basics>blink from the compiler (environment)
  • NOW PRESS upload option from the environment in few seconds u will find a orange light (blinking) at the pin 13.
NOW YOUR SYSTEM (BOARD AND COMPUTER) IS READY TO RUN THE ARDUINO.

reference: arduino.cc

introduction to arduino and its advantages:




Introduction :

               Arduino is an open-source computer hardware and software company that designs and manufacture kits for building digital devices and interactive objects that can sense and control the physical world.

Open source means we can purchased reassembled , or do it yourself kits or make one our-self. The hardware design can be found on (arduino.cc) and the software source code can also be found there also we can use the same software without any modifications.

Basically Arduino comes with Atmel family processors(8bit -32bit). These are one type of development boards. They contain few sets of digital and analog I/O pins that can be interfaced to various extension boards and other circuits. Apart from I/O pins it has serial communication ports UTAR pins PWM pins and so on depending on different boards (ex:uno ,uno adk, mega. tiny and so on). For programming purpose Arduino provides integrated development environment(IDE) based on processing project (processing .org) basically a compiler and can be programmed using c and c++.

Advantages:
1. simple coding techniques
2. flexibility
3. low cost
4. large community and forum support
5. large number of connectivity (sensors)
6. user friendly and one can learn it in less that 10 days for sure
7. no need for soldering and burning code externally
8. plug and play(simply connect to computer and play with it)
9. cross platform
10. open source