Home Automation System

Wednesday, August 26, 2015

ESP8266 Running Mode and Program Mode

Displaying IMG_20150827_085705.jpg

Note: A key programming , ESP8266 V0.9.2.2 version of firmware is changed .
Please add QQ group 120,693,138 in order to obtain more detailed information .
1. Please MTDO and GPIO0 to a low level , GPIO2 placed high.
   If your module does not MTDO, please at least GPIO0 placed low.
   GPIO0 at low level programming model is the high level run mode.
   Attention must use the pull-down resistor to set the level , not directly connected to VCC / GND.
2. Please resetting ( RST refers to low-level pulse ) or re- enter the programming mode on power .
3. Please do not use USB to TTL power leads , use a separate power supply .
   Power quality related to the module is stable , there is a problem please check the power priority .
4. After successful programming , please re-power . Module change the baud rate value 9600 or your last set .
5. Writing aborted , re- power programming.










Further ALL GPIO should connect to VCC/GND with 3.3K resistors to avoid excessive current. 



Monday, August 24, 2015

Arduino RAM Problems

int freeRam() {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

Arduino BIT operation time ;


 void setup() {
  // put your setup code here, to run once:
  DDRB = _BV(PB5);
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  long a = micros();
PORTB |= _BV(PB5);
long b = micros()-a;
Serial.print("Bit Operation TME:");
Serial.println(b);
delay(1000);
PORTB= B00000000;
delay(1000);
long k = micros();
digitalWrite( 13,HIGH);
long m = micros()-k;
Serial.print("Normal Op TME:");
Serial.println(m);
delay(1000);
PORTB= B00000000;
delay(1000);

}

OUTPUT :

Normal Op TME:8
Bit Operation TME:4
Normal Op TME:8
Bit Operation TME:4
Normal Op TME:8
Bit Operation TME:0
Normal Op TME:8
Bit Operation TME:4
Normal Op TME:8
Bit Operation TME:4
Normal Op TME:8
Bit Operation TME:4
Normal Op TME:8

Arduino Port operation


Type of ports in Atmega328p;
Digital and Analog

DIGITAL PORTS 

PORTD : ( PD0 to PD7) 

Pin No : PD0-:( Pin 0 to Pin 7)

example :  PD2 = Pin 2 ;



DDRD = DDRD | B11111100;  // this is safer as it sets pins 2 to 7 as outputs
                   // without changing the value of pins 0 & 1, which are RX & TX 

PORTB : ( PB0 to PB5)

Pin No : PB0-5 : Pin 8 to Pin 13

BV=Bit Value.

PORTB |= _BV(PB5);

/* set bit 0 using _BV() */
PORTB |= _BV(PB5);

/* set bit 0 using shift */
a |= (1<<0);

Thursday, August 20, 2015

Another example for Analog Reading

long readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
  
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);

  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring
 
  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
  uint8_t high = ADCH; // unlocks both
 
  long result = (high<<8) | low;
 
  result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  return result; // Vcc in millivolts
}

 

Copy From ;
http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/


Wednesday, August 19, 2015

Analog data input Arduino

Data input ;

values = analogRead(A0)

Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). The options are:
  • DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)
  • INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328 and 2.56 volts on the ATmega8 

  • EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.
      

       Scaling values ;

0 to 5V give as 0 to 1023 digital values 

minimum voltage that can read is 5/1023 = 4.88mv

when you give power supply to the board through Diode, voltage will reduced up to 4.4V 

then the correction must be 4.4/1023= 4.3mv 


further, it is required sampling of those analog values in for loop at least few hundred 

for ( int i; i<100; i++) { values = analogRead();
 voltage += 4.441*values/1023;}
then average the voltage by dividing the number of samples 

output = voltage/100;

furthermore,  gain must be adjust as per the requirement ; 
( you have to get few values and read the values with external meters and add the gain)

real Volatge = Arduino read voltage values *gain ;

calculate the gain as per the above equation and put the gain to above output ;

output = voltage*gain/100;