text:
bluetooth module with stk500_recv() error
I am trying to dow what is demonstrated in this tutorial. I have altered the original setup a little by adding a level converter to not fry the Bluetooth module and resistors for the LEDs, as well as using only 2 instead of four LEDs (which I adjusted for in code later). other than that I am using the exact same setup, code,and procedure. Yet when I try to run my code on the Arduino. I get the error below. I believe it is due to using Tx/Rx and serial at the same time but I really don't know anything about this. Should I add more libraries?
Should I change the wiring shown in the tutorial link? It seems like I need to use Tx/Rx
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xce
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xce
avrdude: stk500_recv(): programmer is not responding

Here is the code I used from tutorial:
//Coded By: Angelo Casimiro (4/27/14)
//Voice Activated Arduino (Bluetooth + Android)
//Feel free to modify it but remember to give credit

String voice;
int
led1 = 2, //Connect LED 1 To Pin #2
led2 = 3, //Connect LED 2 To Pin #3
led3 = 4, //Connect LED 3 To Pin #4
led4 = 5, //Connect LED 4 To Pin #5
led5 = 6; //Connect LED 5 To Pin #6
//--------------------------Call A Function-------------------------------//
void allon(){
     digitalWrite(led1, HIGH);
     digitalWrite(led2, HIGH);
     digitalWrite(led3, HIGH);
     digitalWrite(led4, HIGH);
     digitalWrite(led5, HIGH);
}
void alloff(){
     digitalWrite(led1, LOW);
     digitalWrite(led2, LOW);
     digitalWrite(led3, LOW);
     digitalWrite(led4, LOW);
     digitalWrite(led5, LOW);
}
//-----------------------------------------------------------------------//
void setup() {
  Serial.begin(9600);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
}
//-----------------------------------------------------------------------//
void loop() {
  while (Serial.available()){  //Check if there is an available byte to read
  delay(10); //Delay added to make thing stable
  char c = Serial.read(); //Conduct a serial read
  if (c == '#') {break;} //Exit the loop when the # is detected after the word
  voice += c; //Shorthand for voice = voice + c
  }
  if (voice.length() > 0) {
    Serial.println(voice);
//-----------------------------------------------------------------------//
  //----------Control Multiple Pins/ LEDs----------//
       if(voice == "*all on") {allon();}  //Turn Off All Pins (Call Function)
  else if(voice == "*all off"){alloff();} //Turn On  All Pins (Call Function)

  //----------Turn On One-By-One----------//
  else if(voice == "*TV on") {digitalWrite(led1, HIGH);}
  else if(voice == "*fan on") {digitalWrite(led2, HIGH);}
  else if(voice == "*computer on") {digitalWrite(led3, HIGH);}
  else if(voice == "*bedroom lights on") {digitalWrite(led4, HIGH);}
  else if(voice == "*bathroom lights on") {digitalWrite(led5, HIGH);}
  //----------Turn Off One-By-One----------//
  else if(voice == "*TV off") {digitalWrite(led1, LOW);}
  else if(voice == "*fan off") {digitalWrite(led2, LOW);}
  else if(voice == "*computer off") {digitalWrite(led3, LOW);}
  else if(voice == "*bedroom lights off") {digitalWrite(led4, LOW);}
  else if(voice == "*bathroom lights off") {digitalWrite(led5, LOW);}
//-----------------------------------------------------------------------//
voice="";}} //Reset the variable after initiating

How did you upload the sketch? With the Bluetooth module still connected? In that case please disconnect it and the upload. Connect again after the upload.

Yes your comment was the solution Thank you so much

How did you upload the sketch? With the Bluetooth module still connected? In that case please disconnect it and the upload. Connect again after the upload.


text:
Refine Colorview Code
How would I refine this to only recognize red and green? I don't need the full functionality of this code, just the ability to distinguish between red and green, and output that respectively.
I also would like to eliminate the bleed over; meaning, the green led stays on slightly when I flood the Adafruit with red light and vice versa. I am not really familiar with the output of the Adafruit, but it seems this could be an analog "question and answer" situation; it's either green or red or nothing.
#include <Wire.h>
#include "Adafruit_TCS34725.h"

#ifndef _TCS34725_H_
#define _TCS34725_H_

#if ARDUINO >= 100
 #include <Arduino.h>
#else
 #include <WProgram.h>
#endif

#include <Wire.h>

#define TCS34725_ADDRESS          (0x29)

#define TCS34725_COMMAND_BIT      (0x80)

#define TCS34725_ENABLE           (0x00)
#define TCS34725_ENABLE_AIEN      (0x10)    /* RGBC Interrupt Enable */
#define TCS34725_ENABLE_WEN       (0x08)    /* Wait enable - Writing 1 activates the wait timer */
#define TCS34725_ENABLE_AEN       (0x02)    /* RGBC Enable - Writing 1 actives the ADC, 0 disables it */
#define TCS34725_ENABLE_PON       (0x01)    /* Power on - Writing 1 activates the internal oscillator, 0 disables it */
#define TCS34725_ATIME            (0x01)    /* Integration time */
#define TCS34725_WTIME            (0x03)    /* Wait time (if TCS34725_ENABLE_WEN is asserted) */
#define TCS34725_WTIME_2_4MS      (0xFF)    /* WLONG0 = 2.4ms   WLONG1 = 0.029s */
#define TCS34725_WTIME_204MS      (0xAB)    /* WLONG0 = 204ms   WLONG1 = 2.45s  */
#define TCS34725_WTIME_614MS      (0x00)    /* WLONG0 = 614ms   WLONG1 = 7.4s   */
#define TCS34725_AILTL            (0x04)    /* Clear channel lower interrupt threshold */
#define TCS34725_AILTH            (0x05)
#define TCS34725_AIHTL            (0x06)    /* Clear channel upper interrupt threshold */
#define TCS34725_AIHTH            (0x07)
#define TCS34725_PERS             (0x0C)    /* Persistence register - basic SW filtering mechanism for interrupts */
#define TCS34725_PERS_NONE        (0b0000)  /* Every RGBC cycle generates an interrupt                                */
#define TCS34725_PERS_1_CYCLE     (0b0001)  /* 1 clean channel value outside threshold range generates an interrupt   */
#define TCS34725_PERS_2_CYCLE     (0b0010)  /* 2 clean channel values outside threshold range generates an interrupt  */
#define TCS34725_PERS_3_CYCLE     (0b0011)  /* 3 clean channel values outside threshold range generates an interrupt  */
#define TCS34725_PERS_5_CYCLE     (0b0100)  /* 5 clean channel values outside threshold range generates an interrupt  */
#define TCS34725_PERS_10_CYCLE    (0b0101)  /* 10 clean channel values outside threshold range generates an interrupt */
#define TCS34725_PERS_15_CYCLE    (0b0110)  /* 15 clean channel values outside threshold range generates an interrupt */
#define TCS34725_PERS_20_CYCLE    (0b0111)  /* 20 clean channel values outside threshold range generates an interrupt */
#define TCS34725_PERS_25_CYCLE    (0b1000)  /* 25 clean channel values outside threshold range generates an interrupt */
#define TCS34725_PERS_30_CYCLE    (0b1001)  /* 30 clean channel values outside threshold range generates an interrupt */
#define TCS34725_PERS_35_CYCLE    (0b1010)  /* 35 clean channel values outside threshold range generates an interrupt */
#define TCS34725_PERS_40_CYCLE    (0b1011)  /* 40 clean channel values outside threshold range generates an interrupt */
#define TCS34725_PERS_45_CYCLE    (0b1100)  /* 45 clean channel values outside threshold range generates an interrupt */
#define TCS34725_PERS_50_CYCLE    (0b1101)  /* 50 clean channel values outside threshold range generates an interrupt */
#define TCS34725_PERS_55_CYCLE    (0b1110)  /* 55 clean channel values outside threshold range generates an interrupt */
#define TCS34725_PERS_60_CYCLE    (0b1111)  /* 60 clean channel values outside threshold range generates an interrupt */
#define TCS34725_CONFIG           (0x0D)
#define TCS34725_CONFIG_WLONG     (0x02)    /* Choose between short and long (12x) wait times via TCS34725_WTIME */
#define TCS34725_CONTROL          (0x0F)    /* Set the gain level for the sensor */
#define TCS34725_ID               (0x12)    /* 0x44 = TCS34721/TCS34725, 0x4D = TCS34723/TCS34727 */
#define TCS34725_STATUS           (0x13)
#define TCS34725_STATUS_AINT      (0x10)    /* RGBC Clean channel interrupt */
#define TCS34725_STATUS_AVALID    (0x01)    /* Indicates that the RGBC channels have completed an integration cycle */
#define TCS34725_CDATAL           (0x14)    /* Clear channel data */
#define TCS34725_CDATAH           (0x15)
#define TCS34725_RDATAL           (0x16)    /* Red channel data */
#define TCS34725_RDATAH           (0x17)
#define TCS34725_GDATAL           (0x18)    /* Green channel data */
#define TCS34725_GDATAH           (0x19)
#define TCS34725_BDATAL           (0x1A)    /* Blue channel data */
#define TCS34725_BDATAH           (0x1B)

typedef enum
{
  TCS34725_INTEGRATIONTIME_2_4MS  = 0xFF,   /**<  2.4ms - 1 cycle    - Max Count: 1024  */
  TCS34725_INTEGRATIONTIME_24MS   = 0xF6,   /**<  24ms  - 10 cycles  - Max Count: 10240 */
  TCS34725_INTEGRATIONTIME_50MS   = 0xEB,   /**<  50ms  - 20 cycles  - Max Count: 20480 */
  TCS34725_INTEGRATIONTIME_101MS  = 0xD5,   /**<  101ms - 42 cycles  - Max Count: 43008 */
  TCS34725_INTEGRATIONTIME_154MS  = 0xC0,   /**<  154ms - 64 cycles  - Max Count: 65535 */
  TCS34725_INTEGRATIONTIME_700MS  = 0x00    /**<  700ms - 256 cycles - Max Count: 65535 */
}
tcs34725IntegrationTime_t;

typedef enum
{
  TCS34725_GAIN_1X                = 0x00,   /**<  No gain  */
  TCS34725_GAIN_4X                = 0x01,   /**<  4x gain  */
  TCS34725_GAIN_16X               = 0x02,   /**<  16x gain */
  TCS34725_GAIN_60X               = 0x03    /**<  60x gain */
}
tcs34725Gain_t;

class Adafruit_TCS34725 {
 public:
  Adafruit_TCS34725(tcs34725IntegrationTime_t = TCS34725_INTEGRATIONTIME_2_4MS, tcs34725Gain_t = TCS34725_GAIN_1X);

  boolean  begin(void);
  void     setIntegrationTime(tcs34725IntegrationTime_t it);
  void     setGain(tcs34725Gain_t gain);
  void     getRawData(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c);
  uint16_t calculateColorTemperature(uint16_t r, uint16_t g, uint16_t b);
  uint16_t calculateLux(uint16_t r, uint16_t g, uint16_t b);
  void     write8 (uint8_t reg, uint32_t value);
  uint8_t  read8 (uint8_t reg);
  uint16_t read16 (uint8_t reg);
  void setInterrupt(boolean flag);
  void clearInterrupt(void);
  void setIntLimits(uint16_t l, uint16_t h);
  void     enable(void);

 private:
  boolean _tcs34725Initialised;
  tcs34725Gain_t _tcs34725Gain;
  tcs34725IntegrationTime_t _tcs34725IntegrationTime;

  void     disable(void);
};

#endif

// Pick analog outputs, for the UNO these three work well
// use ~560  ohm resistor between Red & Blue, ~1K for green (its brighter)
#define redpin 3
#define greenpin 5
#define bluepin 6
// for a common anode LED, connect the common pin to +5V
// for common cathode, connect the common to ground

// set to false if using a common cathode LED
#define commonAnode true

// our RGB -> eye-recognized gamma color
byte gammatable[256];

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

void setup() {
  Serial.begin(9600);
  Serial.println("Color View Test!");

  if (tcs.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1); // halt!
  }

  // use these three pins to drive an LED
  pinMode(redpin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  pinMode(bluepin, OUTPUT);

  // thanks PhilB for this gamma table!
  // it helps convert RGB colors to what humans see
  for (int i=0; i<256; i++) {
    float x = i;
    x /= 255;
    x = pow(x, 2.5);
    x *= 255;

    if (commonAnode) {
      gammatable[i] = 255 - x;
    } else {
      gammatable[i] = x;
    }
    //Serial.println(gammatable[i]);
  }
}

void loop() {
  uint16_t clear, red, green, blue;

  tcs.setInterrupt(false);      // turn on LED

  delay(60);  // takes 50ms to read

  tcs.getRawData(&red, &green, &blue, &clear);

  tcs.setInterrupt(true);  // turn off LED

  Serial.print("C:\t"); Serial.print(clear);
  Serial.print("\tR:\t"); Serial.print(red);
  Serial.print("\tG:\t"); Serial.print(green);
  Serial.print("\tB:\t"); Serial.print(blue);

  // Figure out some basic hex code for visualization
  uint32_t sum = clear;
  float r, g, b;
  r = red; r /= sum;
  g = green; g /= sum;
  b = blue; b /= sum;
  r *= 256; g *= 256; b *= 256;
  Serial.print("\t");
  Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.print((int)b, HEX);
  Serial.println();

  //Serial.print((int)r ); Serial.print(" "); Serial.print((int)g);Serial.print(" ");  Serial.println((int)b );

  analogWrite(redpin, gammatable[(int)r]);
  analogWrite(greenpin, gammatable[(int)g]);
  analogWrite(bluepin, gammatable[(int)b]);

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
How to upload .hex file to Atmega8 Using Arduino IDE and Uno as an Isp?
I want to upload an .hex file to an Atmega8 chip (SMD). I want to use the Arduino IDE and an Uno as the ISP program. But I'm unable to find any details on how to load a sketch which is in .hex format.
Following is the batch file I created to use with avrdude. I would like to know if the Command is correct?
C:\Users\Pranay\Desktop\DIY\arduino-1.0.1!\hardware\tools\avr\bin/avrdude -CC:\Users\Pranay\Desktop\DIY\arduino-1.0.1!\hardware\tools\avr\etc/avrdude.conf -v -v -v -v -patmega8 -cstk500
 -P\\.\COM4 -b19200 -Uflash:w:C:\Users\Pranay\Desktop\DIY\arduino-1.0.1!\hexFiles\Heart.hex:i

pause

It looks okay. Have you tried running it? It can't do any harm if it's wrong; you just get an error message.

When i run the batch file it says "C:\Users\Pranay " is not recognised as internal or external command, operable program or Batch file.
In the next line it says the system cannot find the path specified.

I think that means you got the file-path wrong.

Thanks for your help @Gerben. figured out the mistake and finally sucedded in uploading sketch.

That good to hear. Could you share your solutions, so others might learn from it?

@Pranay Could you please post the solution as an answer to this post. https://stackoverflow.blog/2011/07/01/its-ok-to-ask-and-answer-your-own-questions/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Arduino Google speech api
I'm currently experimenting with my arduino Uno. I control it via an mobile (android) but wanted to just use a microphone on the board so I don't need to carry my mobile around. It is possible to record flac files from a mic and send it to Google speech api and get a return? And then maybe output it via the synthesis.
So it is possible to do this on an arduino uno and with C. If doesnt is there any other way I can go? I could buy a raspberry pi but I don't an whole operating system like linux installed. So any thoughts?

The Uno has only 2k of RAM so I doubt you will be able to record anything much.

You can use a special voice recognition shield (for example: EasyVR Shield 3.0 - Voice Recognition Shield) to integrate a simple and basic voice recognition. I think it's a very fast and easy prototyping way...
For the use of the more complex Google Speech Recognition I would use a more powerful microcontroller (such as Raspberry PI or something like that)...


text:
Saving byte array in PROGMEM instead of SRAM
For an ethernet project I do, I need to store the Ethernet Shield's MAC address.
I store it like that:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0xE1, 0x85 };

That works OK, but in my project I need all the SRAM available, so every byte of memory is important. I've used the F() macro and PROGMEM everywhere, but I couldn't manage to store the MAC byte array in the PROGMEM.
How can I store it in PROGMEM? Is it even possible?

Try "const byte mac[] PROGMEM = { ... };" https://www.arduino.cc/en/Reference/PROGMEM

MAC addresses are usually configurable, so I'd rather store it in EEPROM.

Since the original question indicated the OP was having trouble accessing PROGMEM, s/he may also have problems with EEPROM. Could you perhaps expand your answer with a code snippet that illustrates how your suggestion would work?

As it stands, this would make more sense as a comment. But if you can address the OP's issue – how to store the MAC address outside of SRAM then it would be a good answer.

Related: Can I write to flash memory using PROGMEM? and Writing objects to PROGMEM

See Putting constant data into program memory (PROGMEM) for tips about putting stuff into PROGMEM. However personally I wouldn't get too excited about saving 6 bytes.

Example code:
Declare data globally:
const byte mac [6] PROGMEM = { 0x90, 0xA2, 0xDA, 0x0F, 0xE1, 0x85 };

Get a copy for use into a temporary variable:
  char foo [6];
  memcpy_P (foo, mac, sizeof foo);


text:
Adafruit libary and CC3000 shield
I have a Arduino Uno and a CC3000 shield. When I run the example code for Webclient from Adafruits libary it works perfect.
When I switch out address for reading a corresponding text file from my own server the code completes sporadically. The output in the serial window stops at differens places every time.
Does anyone have any idea how I can fix this?
The Adafruit points to this URL: http://www.adafruit.com/testwifi/index.html
While mine points to this URL: http://a.sjsd.li/test/test.html

Can you show the results you got? All your test page contains is 'hello world' so there should be no problems reading it from the server. What HTTP response do you get?

The response header it HTTP/1.1 200 OK, here you got an example of failure:

HTTP/1.1 200 OK
Server: Apache
Last-Modified: Sat, 16 Jan 2016 11:38:42 GMT
ETag: "c98e4d75-c-52971f630f480"
Vary: Accept-Encoding
Content-Type: text/html
Transfer-Encoding: chunked
Date: Sat, 16 Jan 2016 18:06:16 GMT
X-Varnish: 1632177268 1632051084
Age: 71
Via: 1.1 varnish
Conn

Edit your post to include the response PROPERLY FORMATTED, so we can know what's missing. Is this result consistent? Does the response always cut off at this point?

Please edit your post to include the additional information requested. Select it and hit Ctrl+K to make it monospaced formatting.

Sorry for the bad formating of the code guys. It seems like I can't make it to work. Ctrl + K makes the foucs jumpt to the URL-field in Chrome.
@brianrho No, sometimes it doesen't get this far.

I have arrived at a solution that works for me. Instead of using Adafruit library I have adopted Sparkfuns library.
Some adjustments in the setup for the pins:
#define CC3000_INT      3   // Needs to be an interrupt pin (D2/D3)
#define CC3000_EN       5   // Can be any digital pin
#define CC3000_CS       10  // Preferred is pin 10 on Uno
#define SD_CS           4   // Chip select for SD card

Then some adjustemnt in the block for the HTTP request:
client.print("GET /index.html HTTP/1.1\r\n");
client.print("Host: ");
client.print(server);
client.print("\r\n\r\n");
client.println();
Serial.println();

This is not a solution for the Adafruit libary. But it helped me to continue my project.

Perhaps the CC3000 isn't waiting long enough for the whole response to come in. Try increasing the variable IDLE_TIMEOUT in the Web_Client sketch, near the top. Change its value to 10000 and see if you get the whole response this time.

I have tried to to change the value. But it doesen't help at all.


text:
Ping IP address using ESP8266 connected to Arduino
I want to make a system using NeoPixels, an Arduino and an ESP8266 module to ping IP addresses on my network to determine if certain people are on our Wi-Fi (I'll be pinging mobile phones).
I'm finding it hard to find any help as to how to ping IP addresses from an Arduino using the ESP8266 module. I did find the ICMP Ping library, but it uses the Ethernet shield, and I'm quite new to Arduino so I don't even know if I could modify the library in any way.
If anyone could help me on my way, that'd be great!

I'm not sure the AT firmware has ICMP facilities. You may need to write your own firmware.

AT+PING? https://cdn.sparkfun.com/assets/learn_tutorials/4/0/3/4A-ESP8266__AT_Instruction_Set__EN_v0.30.pdf, 16.
AT+PING – Function Ping, pp. 55.

From what I could find, it seems theres a command for pinging a server. It returns the number of milliseconds taken for the server to respond. The command is: AT+PING="web site" or AT+PING=<ip addr>, from 2 separate sources. You'll have to test them to see which (if not both) is correct.

This answer does not answer your question, but it implements the device you are describing. Unfortunately I don't have enough reputation to comment, so I will post it as an answer.
As people said before, ping is not a reliable option to scan the network. On Linux you can use dedicated (software) tools to scan the network, but even they struggle to reliably detect (some) mobile devices. So I wanted my router to do the work for me (at least it should reliably know which devices are logged into the Wi-Fi, right?).
Fortunately I have a Fritz!Box that provides an API to communicate with. Based on that API and an ESP8266 I build such a device you described in your question: [15min] Weasley Clock / Who is Home Indicator - based on TR-064 (beta).
To do that I wrote a library for Arduino to uses that API: Aypac/Arduino-TR-064-SOAP-Library.

It's too long for a comment anyway. :) I think we'll let it stand.

Not all devices (including) phones respond to ICMP Ping. This may differ for each (mobile) OS and version and phone make and model. But assuming your phone does respond to ping...
If you use the ESP with just the default firmware (a waste of a perfectly capable microcontroller), then indeed use the AT+PING command from the other answers.
If you use the ESP directly, you may be out of luck. Both the nocemcu lua firmware and the arduino api for esp seem to lack icmp ping functionality.


text:
Details on OV7670
I am thinking of working on a project based on a camera module OV7670. I am making a security system using an arduino where detected motion (I am also using a PIR sensor) will trigger the camera module. I wanted to get all kinds of information needed to work with the camera module in this kind of project.

I am not expecting a very long answer rearding everything about the module. The most important points and maybe a few references would be enough. It would also be helpful if programming reference for the camera module is also provided.

This post is a link to a blog that describes the pinout and connections, along with some general information. They also have a link to an "ArduCAM" library with an example utilizing your camera model.


text:
Powering 3.3v sensors from a coin cell
I want to build some small wireless temperature measurement boards, to sprinkle around the house. I'd like to power these from a single coin cell battery (CR2032).
For these I'd like to use the DS18B20 sensor. These sensor require a minimal voltage of 3v. A coin cell will however only provide 3v when it's full, and will drop to around 2.6v when 90% discharged.
From what I've read the DS18B20 will give some strange results when the supply voltage is below 3v. Also the precision can be off, when the supply voltage isn't regulated.
(The ATMega328p and NRF24L01, I plan to use, will work just fine at voltages down to 2v, so only the DS18B20 requires 3.3v.)
So I've come up with the following solutions:

Use two coin cells, and a (low quiescent current) voltage regulator. (Disadvantage: takes more space, more batteries, slightly more expensive.)
Use a boost regulator. (Disadvantage: even more expensive, and a lot more complex (for me at least).)
Implement a voltage doubler to power the DS18B20 when needed (every 15 minutes). To regulate the voltage I'd add a 3.3v zener diode to the output. (dirt cheap to implement)

I tend to lean toward option 3, but my question is, could it even work?
Is there something to look out for?
Or is there an even better solution?
edit I was planning to use the Dickson doubler circuit.

What type of voltage doubler are you considering?

@Majenko A Dickson doubler. See the schematic in my edit above.

A dickson is certainly a possible solution, and is commonly used in battery powered systems to get a higher voltage to run components that need it.  Better though is to not need it in the first place since any voltage conversion will entail losses that will shorten your ideal battery life.

If you are using a doubler you should use Schottky diodes to minimise voltage drop. Using a Zener diode without a limiting resistor would work in this circuit, but is likely to be very inefficient. A series regulator would be better. You could use a feedback circuit to vary the high phase of the clock as a simple switching regulator, and eliminate the Zener.

@Milliways I'll have to calculate the correct capacitor value, and frequency, to match the current needed for the sensor. Any excess current will indeed be lost through the zener.

You're missing out option 4, which is the option I would personally go for:

Use a different temperature sensor.

A quick parametric search on Microchip (my favourite, I'm a Microchip fanboy after all...) I find quite a nice one - the MCP9844.

Microchip Technology Inc.’s MCP9844 digital temperature sensor converts temperature from -40°C and +125°C to a digital word. This sensor meets JEDEC Specification JC42.4-TSE2004B1 mobile Platform Memory Module Thermal Sensor Component. It provides an accuracy of ±0.2°C/±1°C (typical/maximum) from +75°C to +95°C.
Operating Voltage Range (V): +1.7 to +3.6

However it is only available as a TDFN which makes prototyping difficult, although it is one of my two preferred footprints for real building - the other being variants of QFN.
I am sure you can search other makers for similarly specified chips that will do the job without the need for fancy boosters or doublers or the expense of multiple batteries etc.
One of the first steps of any design is the component identification. Often the chip or component that many people automatically reach for because it's the first one they used, or it's the one people most often talk about, may not be the right tool for the job. It pays to shop around a bit and look to see if there is something better that will fit the bill and save cost and time in the long run by ending up with a simpler system.

That's an interesting alternative. I was indeed working backwards on a problem. I wanted to try soldering TDFN/QFN anyways. Thank you. I'll go and search some more alternatives, and see what's available from my regular webshops.


text:
Arduino drawing a bitmap on nokia 5110 lcd
Hello I finally got my nokia 5110 lcd working, I have tested it by displaying bitmap images other people have made. I made my own image and then used lcd assistant to turn it into an array. First look at my code.
#include "U8glib.h"

U8GLIB_PCD8544 u8g(8, 4, 7, 5, 6);  // CLK=8, DIN=4, CE=7, DC=5, RST=6
int x = 5;
int y = 5;
int level = 5;
const uint8_t rook_bitmap[] U8G_PROGMEM = {
0x7E, 0x82, 0x04, 0x8E, 0x7A, 0x42, 0xB4, 0x24, 0x08, 0xD8, 0x48, 0x08, 0x08, 0x0C, 0x02, 0x22,
0xD9, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1E, 0x11, 0x21, 0x22, 0x14, 0x3B,
0xD4, 0x25, 0x29, 0x68, 0xA8, 0xA8, 0x74, 0x0C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
void draw(void) {
  // graphic commands to redraw the complete screen should be placed here
  u8g.drawBitmapP( 5, 5, 3,18, rook_bitmap);
}
void setup(void) {
}
void loop(void) {
  // picture loop
  u8g.firstPage();
  do {
    draw();
  } while( u8g.nextPage() );
// y++;
  // rebuild the picture after some delay
  delay(1000);
}
The part that goes wrong is at u8g.drawBitmapP(5,5,21,18, rook_bitmap);
I know it is to do with the 21 and 18 being wrong because I don't know where to get those numbers. Is it the width and height of the image when it is in paint.net or what is it?

The 21 and 18 are the dimensions of the image. It's not just pixels though.
The first number (21) is the number of bytes in a row of the image - that is one eighth of the width in pixels.  The width must be a multiple of 8.
The second number is the number of rows in the image - basically the height in pixels.
The two numbers, when multiplied together, must equal the number of bytes in your array.
From the documentation:

Description
Draw a bitmap at the specified x/y position (upper left corner of the bitmap). Parts of the bitmap may be outside the display boundaries. The bitmap is specified by the array bitmap. A cleared bit means: Do not draw a pixel. A set bit inside the array means: Write pixel with the current color index. For a monochrome display, the color index 0 will usually clear a pixel and the color index 1 will set a pixel.
Arguments:

u8g : Pointer to the u8g structure (C interface only).
x: X-position (left position of the bitmap).
y: Y-position (upper position of the bitmap).
cnt: Number of bytes of the bitmap in horizontal direction. The width of the bitmap is cnt*8.
h: Height of the bitmap.

It would appear your image data is complete gibberish.  This is what I decode it to be:
 ######  #     #  #
 ###   # # ####  #    #
  # ## #  #  #     #
   ## ##   #  #    #
   #      ##     #
 #   #  #  ## #####

        #        ####
#   #   #    #   #   #
  # #   ## ###    # # ##
# #  #  #  # #     # ##
   # # #   # # #  # ###
  ##    ##

so how do I find the width 21/ 8 because that isn't a multiple of 8

You will have a multiple of 8 regardless. The extra bits will be padded with 0 (or they should be if the converter you used is any good). Count the number of bytes in your array, divide it by the number of pixels your image is high, and that is the value to use. If your source image is 21 pixels wide I would put money on the answer being 3.  3x8 = 24, so 21 + three blank pixels for padding.

ok I'm a little confused what number do I put into u8g.drawBitmapP(x,y,?,8); do I put 3 or 24

3 since that is the number of bytes that would make up a row.  3x8 should equal the size of your array.

I don't know why it dosnt work heres what ive done

u8g.drawBitmapP( 55, 5, 3,18, rook_bitmap); the real image is 24*18 now and it still looks really weird on the screen

With those figures here should be 54 entries in your array, but I only count 47.

I resized the image and now it has 54 but still dosnt work

Then maybe the converter doesn't handle images that aren't a multiple of 8 pixels wide properly. Try using an image that is exactly 24 pixels wide.

no that dosnt seem to work do you want me to send u the code and image

Not really, no. I don't have a display. Update your question with your current version of the code so all can see it.

it is done by the way

Your data is gibberish. It doesn't convert into any form of a recognizable image.

I got it to wrok by using a different image to hex converter I will accept ur answer since u helped me and I did learn a bit

That's good. I was beginning to suspect your converter was either bad or configured wrong.


text:
Link Arduino Uno to Particle Photon
I'm working on a prototype with a Particle Photon, but I've realized the required number of pins is bigger than the number of pins on my photon.
I thought I could have an Arduino Uno wired to some sensors, and link the Arduino to the photon via a Software Serial from the Arduino (as its serial pins will already be busy) to the Serial pins of the photon.
Is it possible, and is there a better way to solve my problem?

https://www.particle.io/

If you just need to get more inputs you could use multiplexing. The multiplexing method is more robust than software serial will be. How to do this is explained here and datasheet for the commonly used cd4051 here
You don't specify what kind of sensors you will use. if the sensors are i2c or similar it is possible to daisychain (multiplex too) them.

Everything is possible, it is programming. People are doing software-only USB on AVRs.
I doubt that the effort is worth it, given how hard it is to debug such low-level code. Besides you can use on-board UART if you don't need the USB connectivity - just disable it.
Main question is - where is the main software run, aka "Who's the Brain"? If Photon, maybe you can use SPI? SPI is dead-simple to emulate in software.

The photon is the brain, the Arduino would provide me with more pins

The USB of the Photon will already be used, do I have options other than softSerial?

Photon has SPI. Arduino Uno has SPI.
Photon has I2C. Arduino Uno has I2C too.
Programming them will be easier than software emulation of UART. I'd try SPI.

Oh, I didn't know this protocol. I'll definitely take a look!

I2C looks very interesting also, especially the fact that it uses only 2 pins and still works with a small voltage difference (5V vs 3.3V)

Yes, I2C is nice to wire, but it's relatively complex to program. SPI is simpler to program than UART, but requires more wires (4 vs 2).


text:
Long Distance Communication with Arduino
I am reading the value of six potentiometers with a TX Arduino and receiving that data and applying those numbers to a motor using serial. It is working fine through TTL but I am going to need to do this over a 60 ft tether.
I have done a little research and see that I could use RS 232 but that the maximum you should go with that is 50 ft, which will not work if I'm not mistaken. I have also seen RS 485 which will give us 4000 ft, which is overkill but will work. However, that only offers one-way communication, if I'm not mistaken. What I'm wondering is which protocol should I convert it to, and how I would have to adjust my RX and TX code.
TX code:
/*
  Transmitting Code
  Reads potentiometers and sends them through serial
*/

int data [10];     // to send bytes
int start [2];
int pot0Pin = A0;  // analog pin used to connect the potentiometer
int pot0;          // variable to read the pot0ue from the analog pin
int pot1Pin = A1;
int pot1;
int pot2Pin = A2;
int pot2;
unsigned char checksum0;
unsigned char checksum1;
unsigned char checksum2;

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  pinMode(19, INPUT);
  pinMode(18, OUTPUT);
}

void loop() {

// READ THE POTENTIOMETERS:

  pot0 = analogRead(pot0Pin);   // reads the value of the potentiometer (pot0ue between 0 and 1023)
  data[0] = pot0 & 0xFF; //least significant 8 bit byte
  data[1] = (pot0 >> 8); //most significant 2 bits

  pot1 = analogRead(pot1Pin);
  data[2] = pot1 & 0xFF;
  data[3] = (pot1 >> 8);

  pot2 = analogRead(pot2Pin);
  data[4] = pot2 & 0xFF;
  data[5] = (pot2 >> 8);

// CREATE CHECKSUMS:

  checksum0 = ~(data[0]+data[1]) + 1;

  checksum1 = ~(data[2]+data[3]) + 1;

  checksum2 = ~(data[2]+data[3]) + 1;

// WRITE VALUES AND CHECKSUMS TO SERIAL:

  Serial1.write(data[0]);
  Serial1.write(data[1]);

  Serial1.write(data[2]);
  Serial1.write(data[3]); //bytes sent

  Serial1.write(data[4]);
  Serial1.write(data[5]);

  Serial1.write(checksum0);

  Serial1.write(checksum1);

  Serial1.write(checksum2); // send the checksum

 delay(10);        // delay in between reads for stability

}

RX code:
/*
  Receving Code
  Reads bytes from Transmitting Code and put thems back together
  Applies the read bytes to our motor control board
*/
unsigned char val[10];    // variable to read the value from the analog pin
int motorVal;
int coolVal;      // 0-1024 received from serial
int coolVal1;
int coolVal2;
unsigned char checksum1;
unsigned char checksum2;
unsigned char checksum3;
unsigned char checkit1;
unsigned char checkit2;
unsigned char checkit3;
int directionPin = 8;
int PWM_out_pin = 9; // works on pins 2 - 13 and 44 - 46

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
//  Serial1.begin(9600);
  pinMode(10, INPUT);
  pinMode(18, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
}

void loop() {

  if (Serial1.available()>5) {

    val[0]=Serial1.read();         // least significant 8 bits
    val[1]=Serial1.read();         // most significant 2 bits

    val[2]=Serial1.read();
    val[3]=Serial1.read();

    val[4]=Serial1.read();
    val[5]=Serial1.read();

    checksum1=Serial1.read();
    checksum2=Serial1.read();
    checksum3=Serial1.read();// get the checksum last

    checkit1 = val[0]+val[1]+checksum1;
    checkit2 = val[2]+val[3]+checksum2;
    checkit3 = val[4]+val[5]+checksum3;

  if (checkit1==0);  {
    coolVal = val[1]<<8 | val[0]; }

  if (checkit2==0);  {
    coolVal1 = val[3]<<8 | val[2];}

  if (checkit3==0);  {
    coolVal2 = val[5]<<8 | val[4];
    }

    Serial.print(coolVal);
    Serial.print(" ");
    Serial.print(coolVal1);
    Serial.print(" ");
    Serial.println(coolVal2);
    delay(10);

  }

// FOR MOTOR 1 (more will be added once we achieve successful serial):
  if (coolVal > 550) {
    digitalWrite (directionPin, HIGH);
    motorVal = map(coolVal, 550, 1023, 0, 1023);
    analogWrite (PWM_out_pin, motorVal / 4); }

  if ((coolVal < 550) && (coolVal > 500)) {
    digitalWrite (directionPin, HIGH);
    analogWrite (PWM_out_pin, 0); }

  if (coolVal < 500) {
    digitalWrite (directionPin, LOW);
    motorVal = map(coolVal, 0, 500, 1023, 0);
    analogWrite (PWM_out_pin, motorVal / 4); }

}

You're right that 60' exceeds the spec for RS-232. That said, distance specs are often quite conservative (as they should be, the spec is a promise that it will work and needs to account for marginal components and an unfavorable environment). I think the 50' limit for RS-232 was more observed in the breach than in practice. So for starters I'd be inclined to see if you could get 60' using RS-232 – I'd be kind of surprised if it didn't work.
Since reliability is important you're doing the right thing by checksumming and checking the data. If the checksum you use is good, it will go a long ways towards letting you detect corrupted data. Then, even if you are using a less than perfect underlying medium (e.g., RS-232 over a long distance), you can improve reliability by ignoring any corrupted values you receive. What that won't protect you from is a major data loss – for example a cut in your cable or a very noisy environment where most of your messages are getting lost. To defend against that you need a mechanism that also acknowledges your transmissions.
So, at this point you've got a choice – you could keep thinking of what might go wrong and designing solutions, or you could see if you could build on existing work. One thing you might want to look at is using something like the SLIP (Serial Line IP) protocol which was developed to run TCP/IP over a dialup modem back in the dark ages of the Internet. I found, but haven't tried out, a couple of implementations for the Arduino:

SerialIP Library for Arduino - a "proof of concept" version on the Arduino Playground.
Open Sound Control over SLIP - newer, but not sure how hard it would be to extract out the SLIP part.

RS-485 is (can be) bi-directional, you just need a transmitter and receiver at each end. Another approach would be to use a 4-20 mA current loop.
You might also want to look into making the controller wireless. That would get you some added convenience (at the expense of a tether to help you find where you put the box) as well as a reliable two-way communication protocol.

I would say the same but this has to be very reliable. It seems that the farther it'll go the less reliable it'll get. What do you think?

Why do you need it to be very reliable? You are already adding checksums, and sending the data every 10ms. It seems to me like some loss wouldn't be that much of a problem. Though extended durations of loss would be.

So dlu, do you think that if using the checksums RS-232 makes the most sense? We want our tether as light as possible so it would be helpful to have just the three wires from RS-232 vs. the two twisted pair on RS-485, as we plan on having the RX code also transmit some information back.

Also, @dlu, am I not using the checksum correctly in my portion of code that states:  if (checkit1==0);  {
coolVal = val[1]<<8 | val[0]; }

Since you need a reliable way to get the values from your tether then checksumming is a really good idea – it helps you know that you got the data you sent. Then the choice of medium (RS-232 vs. 485 vs. current-loop) can be based on other considerations – for example, cost or ease of use. Not that you should ignore the reliability of the underlying medium, but now you have a way to be more confident of it. Since there is no guarantee that the medium is good (e.g., the cable could get disconnected or cut) sending information back is a good thing, it further ensures reliability.

My apologies, after reading your comment and your code more carefully, it does look like the checksum is being used. I'm sorry about that. However, I notice that you're not initializing any of the coolVal* variables. I'd (strongly) suggest doing that, both as documentation and as a guard against the possibility that the compiler doesn't set them to 0 (hangs head and admits that he doesn't remember what the standard says here).

@dlu - I thought I was using the checksums but when viewing the Serial Monitor I'm not getting correct values, it seems some bytes are shifting. Is there a reason for this?

9600 baud isn't very demanding by today's standards. I'd try going the 60' with RS-232. Maybe you'd need to use a shielded cable if your environment is noisy. Try sending some readable strings that you can quickly check by just reading, such as "The quick 9600 baud data string leaps over the fifty foot barrier." or some such. :)  You'll know quickly whether your data got walked on or your checksum calculations are failing.

@MichaelGeorgariou - one reason could be the Serial1.available() > 5 test. I think it is wrong, since you need to read 9 bytes to get your checksum and data.

Another thing to keep in mind is that you don't currently have any way to sync up your transmitter and receiver, you just assume that you'll get a complete packet each time. You should probably be sending a "Start of Message" byte (some value that will never appear as part of the normal data stream) that you search for before starting to read values.

@dlu What could I use for the Start of Message byte?

It could be anything – thinking about it, it doesn't have to be a value that doesn't show up else wise. You just start by looking for it. If it is in the "wrong" place then the checksums will fail and you'll need to start over. Eventually you should (will) sync.

You can do two-way communication with RS485. I have a page about RS485 with schematics and code, including calculating checksums.
You don't have to use twisted cable, that would just add to the reliability. You would need 4 cores (power, ground, A and /B) however if the other end was self-powered (ie. a battery) then you could skip that. There has been a bit of debate about whether the ground wire is needed (assuming you don't send power) but it is probably sensible to include it.
The page I linked above also describes a rolling master system, where each node has a chance to "talk" to other nodes. This demonstrates that you can send and receive on the same pair of wires.
In my test of the rolling master (using UTP cable) I had it working over 40 meters (ignore the figure on the schematic). So your 50 feet range should be easily achievable.

Thanks, Nick. The reason we're hesitant is that we want to limit the amount of wires in the tether, because we are under a weight limitation and would like to have as much as backup weight allocation as possible. Another rule is not being able to have a power source on the other end.


text:
Arduino U8glib: how to display text?
I have a Nokia 5110 screen using u8gliv. I have it displaying an image and I can get it to display text:
   u8g.setFont(u8g_font_osb18);
   u8g.drawStr(0, 20, "PRESS START");

The problem is that this font size is way too big. How can I make it smaller? Do I have to use different fonts? If so how do I do that?

Can somebody explain me how to download a font and upload then to m

Just choose a smaller font. You know, I showed you the documentation earlier. You really should read it, because it contains all the information you need.
For instance, here is the section on the available fonts: https://code.google.com/p/u8glib/wiki/fontgroup - each section contains a link to download the font group which of course you will need to do before you can use it.
You might find something like:
u8g.setFont(u8g_font_fixed_v0);

more to your liking. And don't forget to download it via the link above first.

sorry, I did read it but I couldent find much on font size

It took me 5 seconds - click the setFont link, then the see here for an overview link, then select a group and see what looks nice. They are real size.


text:
Difference between /dev/ttyACM0 and /dev/ttyS0 (Arduino IDE ports under Linux)
I use the Arduino IDE to upload sketches to my Arduino Uno. My OS is Linux Ubuntu 14.04 LTS. The Arduino IDE has two ports by default for communication with the Arduino Uno:
/dev/ttyACM0
/dev/ttyS0

What is the difference between these two ports ?
What does "ACM0" and "S0" mean ?
Are there configuration files somewhere in the OS folder structure that describe the parameters of these ports ?

I know that when I select /dev/ttyACM0, I am able to send data to my Arduino Uno. However it does not work when I select /dev/ttyS0.
I just want to better understand what these ports are exactly.

/dev/ttyACM0 is a USB communication device (CDC) of sub-type "abstract control model" (ACM). That is what the Arduino is.
/dev/ttyS0 is a hardware serial port - the (typically) 9-pin D connector on the back of your computer.
If you want to use /dev/ttyS0 (why would you?!) you will require a special cable that converts the RS-232 voltage signals from the 9-pin D connector into the right TTL level signals for the Ardiuno and wire it in to the right pins on the board.

Thank you for your clarification. Can You help how to upgrade firmware on Sim800 using Sim 800 Serious tool for Linux as it mentioned `Usage: mtkdownload  ROM_VIVA
: /dev/ttyS0,/dev/ttyS1,/dev/ttyS2..
means  COM1,COM2,COM3,COM4,USB2COM
ROM_VIVA is updating rom file
 Y,N
means  format FAT or not format Fat
Example: mtkdownload 100 ROM_VIVA Y
and When I use ./mtkdownload /dev/ttyACM0 ./ROM_VIVA ` It just print same above.

Some high-level languages (e.g. matlab) treat all serial ports as the  /dev/ttyS# selecter.  To interface with an Arduino with MATLAB you have to rename /dev/ttyACM0 as /dev/ttyS#.
This may also be an option in the Arduino IDE, and that is why those options exist.

why would you rename it when a symlink could do the trick ?


text:
Use ESP8266 as WiFi client connected to Arduino Pro Mini
So i'm trying to use the PubSubClient Library on my arduino mini pro, but I'm connecting to the internet via wifi using an ESP8266.
Using a mini means I have to use software serial to connect to the ESP, but I've ran into a problem. I can't find anywhere such as ESPWiFiClient to use with the examples from the PubSubClient library where they use EthernetClient.
Is there any available libraries that can emulate EthernetClient with an ESP module over software serial?

Is there a specific reason for using the pubsubclient library? There are other mqtt libraries out there which do work with the esp8266... I do however completely agree with the answer below that ditching your Arduino and uploading the Arduino code to your ESP8266 is a much better approach.

Ditch the Pro Mini.  Upload your Arduino code to the ESP directly. There's a GitHub repo with the details. ESP for Arduino IDE has a ton of libraries. I'm sure you'll find it there.
But if you're bent on using the Pro Mini,  you'll have to use AT commands over serial to control it or flash a custom firmware into the ESP using Lua or something. And Pro Mini can use its hardware serial just like a Uno does.


text:
Communication between Arduino and XBee
I have two XBee Pro S2Bs: one is plugged in to a USB explorer, and; the other is plugged into an Arduino Wireless Protoshield, which is connected to an Arduino Uno.
My XBee connected to the explorer is configured as the coordinator in AT mode, and the XBee connected to the Arduino is configured as a router in AT mode. As a side note, I tested the network with a second USB explorer, and I was able to communicate between both XBees.
I uploaded the following code to the Arduino (which is just a sample I pulled off the internet somewhere):
char rx_byte;

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    if (Serial.available() > 0)
    {
        rx_byte = Serial.read();
        Serial.print("You Typed: ");
        Serial.println(rx_byte);
    }
}

Once I upload the code and turn on the serial monitor for the Arduino (using either the Arduino IDE or Visual Micro, with the Arduino plugged in via USB), and turn on the serial monitor on for the XBee connected to the USB explorer (using the serial monitor in XCTU), I get the following results:

If the wireless proto shield has its switch set to USB mode, then I can send data from the Arduino serial monitor to the serial monitor in XCTU, but the Arduino serial monitor doesn't receive data that is typed into the XCTU serial monitor.
If the wireless proto shield has its switch set to Micro mode, then I get mostly the opposite result.  I can send data from XCTU serial monitor to the Arduino serial monitor, which the result is returned to the XCTU serial monitor, e.g., if I type "X" in XCTU serial monitor, both serial monitors say "You Typed: X".  However, if I try to send data through the Arduino's serial monitor, neither serial monitor displays anything.

What I would like to do is be able to type in either serial monitor and have the data displayed in both serial monitors, like you would expect in a simple chat program.
Can someone see where I have gone wrong and/or how to get to the correct result?

Check out https://learn.sparkfun.com/tutorials/xbee-shield-hookup-guide/example-communication-test
Essentially you need to set up Software Serial for your xbee to communicate on a couple of digital pins, instead of using hardware serial. When using hardware serial (the RX and TX pins) only one device works on it at a time, hence why you can't use the xbee and the serial monitor at the same time.


text:
Bluetooth connection to HC-05 paired but not connected (in Linux)
I have an Arduino Uno connected to an HC-05 Bluetooth sender/receiver chip. I am trying to create a Bluetooth connection between my Acer laptop running under Ubuntu 14.04 LTS and the HC-05 chip.
Ubuntu detects the HC-05 chip, as can be seen below.
phodor@ubuntu: hcitool scan
Scanning ...
    11:22:33:44:55:66   HC-05

I am able to create a pair between my laptop Bluetooth device and the HC-05 chip. However, I am unable to create a connection with that pair from the Ubuntu interface. The "Connection" button cannot be clicked on, as you can see on the figure below.
I tried creating a connection using the terminal, but after that the terminal still did not detect any connection.
phodor@ubuntu: sudo hcitool cc 11:22:33:44:55:66
[sudo] password for phodor:
phodor@ubuntu: hcitool con
Connections:

I also checked that my computer Bluetooth device was working.
phodor@ubuntu: hcitool dev
Devices:
    hci0    AA:BB:CC:DD:EE:FF

Any idea why the connection cannot be created ? Any idea on how to do it using the Ubuntu interface or the terminal ?

You can find the answer in the Bluetooth connection to HC-05 paired but not connected
Step;
1.Once you have paired the HC-05 as you've described, bind the device by entering;
sudo rfcomm bind 0 "MAC address" 1

2.To trigger the connection & display the data using minicom, run;
sudo minicom -D /dev/rfcomm0

You'll notice that port /dev/rfcomm0 will be available from the arduino IDE as well.
3.To exit minicom, press ctrl+A and then X.

you can try this website for more information
http://wiki.micropython.org/official-accessories/Bluetooth-module-HC05

Link-only answers are frowned upon at Stack Exchange. The answer should at least summarize what we would find if we followed the link. Plus, the link might go down. Please expand your answer.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Arduino String problem
Hello I am using the u8glib library to draw text on the string but it keeps giving me an error with the string
 String name1 = "";
 ...
 void draw(){
  u8g.setFont(u8g_font_micro);
  u8g.drawStr(22, 37, name1);
 }

why dosnt this work?
Here is the error:

C:\Program Files (x86)\Arduino\libraries\U8glib/U8glib.h:200:16: note:
  no known conversion for argument 3 from 'int' to 'const
  __FlashStringHelper*' no matching function for call to 'U8GLIB_PCD8544::drawStr(int, int, String&)'

String is evil and should be avoided at all costs (http://hacking.majenko.co.uk/the-evils-of-arduino-strings)
The author of u8glib knows that and has refused (quite rightly) to implement them.
You should not use String either.  If you really must for some obscure reason then you will have to pass the internal "C string" reference to the drawStr function instead of the whole String object:
u8g.drawStr(22, 37, name1.c_str());

The only reason people use String is because they are too lazy to learn the proper way of handling textual data in C.

The link is broken: "Hmm. We’re having trouble finding that site. We can’t connect to the server at hacking.majenko.co.uk."

Re "String is evil": I have come to the same conclusion, after some pain. It was there all along, but it didn't really show up until now. It was used in formatting of error reporting going to the serial port and as the frequency of (spurious, harmless) errors increased due to some changes to the system, occasional hard freezes was the result. Strangely, it was dependent on the Serial Monitor (or another terminal, like Screen) being open/connected... It being open made the error nearly 100% reproducible.

cont' - That was with an Arduino Leonardo.

If they shouldn't use String, what should they use instead? Perhaps add something to this effect to the answer? And/or a reference to this answer.

Like the documentation says, that method doesn't take a String object. Call the c_str() method of the String object and pass that instead.

what do you mean, what should I put in my arduino code? I looked at the documentation and i cant see a c_str() method

name1.c_str()


text:
uno + ethernet sheild(wiznet) + dh22 temp humidity sensor + viewing data online
i am new to arduino and have no experience with programming
i have an uno r3 board, a wiznet ethernet sheild, and dh22 temp and humidity sensor.
  I would like to have it update plot.ly to view the data.

error returned on monitor is ...
POST /clientresp HTTP/1.1
Host: plot.ly:80
User-Agent: Arduino/0.6.0
Content-Length: 340

version=2.3&origin=plot&platform=arduino&un=jozef.jones&key=tgcio4brx1&args=[{"y": [], "x": [], "type": "scatter", "stream": {"token": "ke1f6fwqas", "maxpoints": 100}}, {"y": [], "x": [], "type": "scatter", "stream": {"token": "k5lmga9qrl", "maxpoints": 100}}]&kwargs={"fileopt": "overwrite", "filename": "filename", "world_readable": true}
... Sent message, waiting for plotly's response...
HTTP/1.1 200 OK
Content-Type: application/json
Date: Sun, 17 Jan 2016 16:22:32 GMT
Server: nginx/1.8.0
Set-Cookie: csrftoken=WknqVtPqjTYvlTyoKSC5QehqDgmt7Qp7; expires=Tue, 17-Jan-2017 16:22:32 GMT; Max-Age=31622400; Path=/; secure
Set-Cookie: anoncsrf=2UDFDiQhQq1zf5MIMaoRJ0ayaqs7g58R; expires=Mon, 18-Jan-2016 16:22:32 GMT; httponly; Max-Age=86400; Path=/
Vary: Accept-Encoding
Vary: Cookie
X-Frame-Options: SAMEORIGIN
Content-Length: 138
Connection: keep-alive

{"url": "", "message": "", "warning": "", "filename": "", "error": "Missing required POST parameters: platform un key origin args kwargs"}

code is
#include <SPI.h>
#include <Ethernet.h>
#include "plotly_streaming_ethernet.h"
#include "DHT.h"

#define nTraces 2

char *tokens[nTraces] = {"ke1f6fwqas", "k5lmga9qrl"};
// arguments: username, api key, streaming token, filename
plotly graph("jozef.jones", "tgcio4brx1", tokens, "filename", nTraces);

// DHT Sensor Setup
#define DHTPIN 2 // We have connected the DHT to Digital Pin 2
#define DHTTYPE DHT22 // This is the type of DHT Sensor (Change it to DHT11 if you're using that model)
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT object

byte mac[] = { 0x00, 0xAA, 0xBB, 0x00, 0x00, 0xCC };
byte my_ip[] = { 192, 168, 1, 117 }; // google will tell you: "public ip address"

void startEthernet(){
    Serial.println("... Initializing ethernet");
    if(Ethernet.begin(mac) == 0){
        Serial.println("... Failed to configure Ethernet using DHCP");
        // no point in carrying on, so do nothing forevermore:
        // try to congifure using IP address instead of DHCP:
        Ethernet.begin(mac, my_ip);
    }
    Serial.println("... Done initializing ethernet");
    delay(1000);
}

void setup() {
  graph.maxpoints = 100;
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  startEthernet();

  bool success;
  success = graph.init();
  if(!success){while(true){}}
  graph.openStream();
  dht.begin();
}

float h, t;

void loop() {
      h = dht.readHumidity();
      t = dht.readTemperature();
      graph.plot(millis(), t, tokens[0]);
      graph.plot(millis(), h, tokens[1]);
}

Seems to be a more common problem (http://community.plot.ly/t/arduino-streaming-data-issue-missing-required-post-parameters/304). You should encode the values of args and kwargs. But that didn't fix the error message when I tried it myself.


text:
Bluetooth help with Arduino Due
I have been able to establish a successful connection between an RN-42 Bluetooth module and Arduino Uno, but I could not do the same with an Arduino Due. The module connects to the phone but whatever data I send is not registered. What is different on the Due in the context of Bluetooth connectivity? Baud-rate perhaps?

do you use hardwareserial or softserial? are you sure that you hooked up the rx tx as well as pwr and gnd correctly?

Please show your code and explain which pins the Bluetooth is connected to on both boards?

int ledPin = 13;
int state = 0;
int flag = 0;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial1.begin(115200); // Default connection rate for my BT module
}
void loop() {
if(Serial.available() > 0){
state = Serial.read();
flag=0;
}
if (state == '0') {
digitalWrite(ledPin, LOW);
if(flag == 0){
Serial.println("LED: off");
flag = 1;
}
}
else if (state == '1') {
digitalWrite(ledPin, HIGH);
if(flag == 0){
Serial.println("LED: on");
flag = 1;
}
}
}

The pins are:                                                                                5v(RN-42) -->  5v (Arduino due),                                                                       GND(RN-42) --> GND(Arduino due),                                                       RX(RN-42) --> TX(Arduino due),                                                                   TX(RN-42) --> RX(Arduino due),                                                                      these are the project details @VisualMicro

Lastly, when I had 9600 as my baud rate in the code it didn't work.

Please edit your question and put the code and additional details there, not in the comments.


text:
Gboard 800 (SIM900 + ATmega 328)
Greetings dear reader!
I have some trouble storing my IMEI code inside a variable. It always returns an error: "void value not ignored as it ought to be".
Since then I tried to write it to the serial line by just running the gsm.SimpleWriteln("AT+GSN"); AT command, but I am stuck at storing this displayed value inside a variable. Does anyone here know a way to store a serial value into a variable? I just want to send the IMEI code as an identifier to the cloud application...
Thanks in advance, your response is really appreciated.
The code:
#include "SIM900.h"
#include <SoftwareSerial.h>
//#include "inetGSM.h"
//#include "sms.h"
//#include "call.h"

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.

//Simple sketch to communicate with SIM900 through AT commands.

//InetGSM inet;
//CallGSM call;
//SMSGSM sms;

int numdata;
char inSerial[40];
int i=0;
boolean startUp = false;

void setup() {
  Serial.begin(9600);
  Serial.println("GSM Shield testing.");

  //Start configuration of shield with baudrate.
  //For http uses it is recommended to use 4800 or slower.
  if (gsm.begin(9600)) {
    Serial.println("\nstatus=READY");
    getIMEI();
  } else Serial.println("\nstatus=IDLE");
};

void loop() {
  //Read for new byte on serial hardware,
  //and write them on NewSoftSerial.
  serialhwread();
  //Read for new byte on NewSoftSerial.
  serialswread();
};

void serialhwread() {
  i=0;
  if (Serial.available() > 0) {
    while (Serial.available() > 0) {
      inSerial[i]=(Serial.read());
      delay(10);
      i++;
    }
    inSerial[i]='\0';
    if(!strcmp(inSerial,"/END")) {
      Serial.println("_");
      inSerial[0]=0x1a;
      inSerial[1]='\0';
      gsm.SimpleWriteln(inSerial);
    }
    //Send a saved AT command using serial port.
    if(!strcmp(inSerial,"TEST")) {
      Serial.println("SIGNAL QUALITY");
      gsm.SimpleWriteln("AT+CSQ");
    } else {
      Serial.println(inSerial);
      gsm.SimpleWriteln(inSerial);
    }
    inSerial[0]='\0';
  }
}

void serialswread() {
  gsm.SimpleRead();
}

void getIMEI() {
  long IMEI = gsm.SimpleWriteln("AT+GSN"); // IMEI code
  Serial.println(IMEI);
  return IMEI
}

Can you maybe share your code?

Ofcourse but it is not complete yet, because I dont have a clue on what to do next;P

gsm does not name a type, probably because you did not create an gsm object. Something like: CallGSM gsm; should be at the top of your sketch (not in comment).

The SimpleWriteln() function just sends an instruction. It doesn't return anything.  Once you have sent the instruction to retrieve the IMEI you then have to actually read the IMEI.
However, fortunately, there is a function that does it for you:
char imei[20];
gsm.getIMEI(imei);

The IMEI should now be in the C string imei. What you do with it then is up to you.

Many thanks man!, but i still get an error. Namely: " 'gsm' does not name a type :\ i looked through all the documentation and couldnt find in the GSM.h library any function that contains .getIMEI() any other advice on tackeling this problem? thanks apreciate the support;)

Well, you're using gsm.* throughout your program - but it looks like you didn't bother to define it (or it's defined by the library but you have the wrong library?)

Yeah I think it is a library related problem to, because if I read the GSM library I don't see any word that contains the GSM.GetIMEI(). But I need this GSM library... so I can't easily swap them out. Do you have any advice on this? On how to make them both compatible within the same file?
I'm really grateful that you help me with this, because I was really  losing hope with this project;)

I was looking at the library linked to by the product page. Are you trying to use a different one? The other commands you use are in the library I was looking at...

I'm using the one they specified, maybe I have an old version I will try to update it, and try to work with the one they currently have on there site;) I will come back on this topic thanks!


text:
"Update driver software" not showing. :(
I've followed tutorials installing arduino drivers for a while, but this is getting in my way:

The all-important "Update driver software" button isn't showing? Can anyone explain this and how I can fix it? Many thanks!

Simple solution: Upgrade to Windows 10 and you won't need the drivers. Ditch Windows 8, it's the most dire piece of *&$"!^ ever created. Even worse than Windows ME.

What arduino are you using official/unofficial? Using any tools to connect the arduino to the pc? I would recommend to reinstall arduino. And or try connecting the device to another USB port

I'm using arduino UNO R3 , I'm using USB to connect my arduino. I'll try another port

Thanks, but I'd get tonnes of new problems if I upgrade to windows 10. Lots of software I have has admitted to glitching a lot on windows 10.

But I am considering upgrading to windows 10.

do you know any other solutions?

Upgrade to Linux and you won't need any drivers either.


text:
Do I have to use an RTC to build a clock?
While I was researching ideas for an Arduino clock, I found several clocks that incorporated an RTC (Real Time Clock) module.
I don't know why it is used in some clocks.
So, here are my questions:

How does an RTC module work?
Do I have to use it "like a rule" (is an RTC necessary or unnecessary) in my clock?

It is only necessary if you want the clock to keep accurate time.  ;-)

Or if you want to set alarms:  https://arduino.stackexchange.com/questions/30638/how-to-set-alarms-on-the-ds3231-easily

How does a RTC module works?

It counts. As simple as that. Once a second it ticks and counts up. It also remembers - most have a battery backup and will continue ticking when you turn the main power off.

I have to use it "like a rule" (if it is necessary or unnecesary) in my clock?

If you want accuracy and continuation, yes.  An RTC is designed to tick at (as close as reasonably possible) once per second. Trying to do that with just an Arduino is incredibly difficult. The ceramic resonator on an Arduino is not as accurate as the quartz crystals used with an RTC. After a week you may find you are an hour out.

RTC modules are used because they make it easier to keep accurate time. They do this by maintaining time when the system is shut down or rebooted (by way of a battery or some other mechanism for keeping running independently of the host system) and by providing a time base that is, usually, more accurate than that of the host.
Another way to keep very accurate time (potentially better than you can get with all but the best RTC modules) is to get your time from a GPS or from the Internet using NTP. If you're going to use a GPS anyway or need an Internet connection then either of those approaches are very good ways to go. If you don't, then they are considerably more expensive than an RTC module.

I built a clock designed a while ago by Geoff Graham, who synchronized to a GPS around every 24 hours, and used the internal clock in-between. The GPS corrected for drift in the internal clock (and, of course, gave you the time accurately in the process).
This is more expensive than a RTC, but more accurate. If you also had an RTC it would drift less during the day. Or, you could read from the GPS all the time and not have an RTC.
I made a GPS clock myself which does that - just shows the GPS time.

Higher-contrast image:

Internals:

This is another project that uses an RTC clock chip (indicated on photo):

However if you go for just an RTC chip you can expect it to drift over time. They are more accurate than counting processor ticks (and survive a power outage because of the backup battery) but are not as accurate as the GPS.
Those clock chips are pretty cheap. I got 30 of them for $10 from eBay.

How does a RTC module works?

It is a specialized counter. It counts seconds, minutes, hours, days, months and years, properly handling such annoying problems as leap year, different days in months, etc.
Additionally it allows powering with a battery, so that clock ticks even when the device is not powered on, until battery discharges.
Usually RTC is clocked at 32768Hz using standarized quartz crystal.

I have to use it "like a rule" (if it is necessary or unnecesary) in my clock?

Unless your microcontroller has RTC built-in, you should use an external one. There are many RTCs with I2C interface.
Built-in timer available in Arduino is not accurate enough and cannot tick when you remove power. Inaccurate counter will cause your clock to drift considerably and no backup power forces your clock to be connected all the time.
You can check out this example to see how to hook up:
https://iobtoolkit.com/docs/tutorials/i2c_terminal_mcp7940n.html
Disclaimer: i'm the author of IOB, but you don't need to use it. It's just a nice analysis of a rather popular RTC.

For this "rule", and for many "rules" like this, the answer is "it's more of a guideline" (usually "it's not required, but may be easier that way").
Keeping time requires 3 things: an accurate "tick", a way of knowing the time initially, and counting the time since then.
The (16mHz) clock on the Arduino will give you a reasonably accurate "tick" - on the order of 50 parts per million. That means, over a million seconds, your clock will drift about 50 seconds. This works about (ballpark) 1 minute per fortnight. Is this accurate enough? This depends on what you are using it for.
The next thing on the list is knowing the time initially. If you buy a RTC, it may be set to the right time, or it may not. Even if it is "set", it may not be set to your timezone. Setting these is pretty easy. It will need to be set every time the clock (be it a RTC or your homebrew clock) loses power. For this reason, RTCs usually have a battery back up. How will your clock get it's time when it starts up? Note that, if your project is network connected, you may be able to get the clock from the internet - this will also mean the drift of your clock will not be an issue - you can retrieve it once per day, so it will never drift more than 4 seconds before it gets corrected.
The final thing that it needs (and the easiest) is a way of counting the time. This is probably the easiest - use the millis() function. Note that this overflows (resets to 0) after 4294967296 milliseconds - about once every 50 days. Millis() will tell you the number of milliseconds since the Arduino last rebooted. If you want your clock to run more than 50 days, you need to be prepared to that. This will happen part way through a second.
Note that this will give you milliseconds, and, fairly easily, seconds, minutes, hours. If you want the day (of the month), then you need to keep track of which month and year, since the length of each month will vary, as will leap days.


text:
İs there any way different way than GND's Arduino
İ'm making  a project on my arduino uno when i figured out i had no more GND left to finish the circuit. İs there any other way to optimize, use pins as input maybe. İ tried whit other websites, however, they weren't much of a use. Can you show an example also.
Thank you sooo much in advance,
Dario

Can't you just connect multiple GND wires to one GND on the board?

No, two wires don't fit into one slot

connect them outside...

Dario,
There are only 3 ground pins on the Arduino Uno, but don't be afraid to "breakout" these pins with wire. It doesn't matter if you connect multiple component grounds together, as long as they are connected to ground with no resistance between them, the circuit will close.
Strip board and pin headers will help you here, try this: http://www.instructables.com/id/Home-Made-Arduino-Prototype-Shield/


text:
Connecting Arduino To mains
How would iconnect my Arduino Mega to house Mains, without buying a transformer, and having to make a whole setup for that.  Can i just use a regular phone adapter?  Or is 1 Amp too large (or 2 Amps).

Amps tell you how much current you can draw from the power supply, or "how much it can do".
You can hook up 3Amps power supply to a device that draws 1Amp and it will work ok, still having 2 amps of reserve.
You must pay attention to power supply voltage and keep it in specified range.
Arduino Mega has recommended input voltage of 7-12V, so you must deliver at least 7V. There are plenty of cheap wall power supplies with voltage regulation from 1.5V to 12V.
How much current it will draw depends on your application, but I doubt that you can suck more than 0,5-1A in a typical application.

Okay, so that is what I thought, because I have read this before that it depends what the device wants.  But then i also saw someone say that it will hurt the Arduino.  But thanks for the clarification!

Note that the ~7v minimum concerns the power connector.  An Arduino can also be powered with an already regulated 5v via the USB connector.  If a phone "charger" (really USB power supply) is doing what it is supposed to, and properly isolated, that would work.  But some things sold as phone charges reportedly do not do what they are supposed to or lack sufficient isolation to be safe.


text:
Signal a LOW level interrupt with an RTC
I'm trying to figure out how to use an RTC to send interrupts to my arduino. I'm using a DS3232. I can get an 'edge' interrupt, with the following toy code (I know the code is silly, it's just a short example to test if I have actually set the RTC to send the interrupt, and that the Arduino receives it):
/*----------------------------------------------------------------------*
 * Minimal example of setting a recurring alarm with the DS3232 RTC     *
 * Attach an LED to pin 7, which will flash when the alarm fires.       *
 *                                                                      *
 * Attach the RTC SQ/INT pin to Uno pin 2, with a 10K pull-up to VCC.   *
 * Ard pin A4 -> RTC SDA, Ard A5 -> RTC SCL, 5v -> vcc, GND -> GND      *
 *----------------------------------------------------------------------*/

#include <DS3232RTC.h>        //http://github.com/JChristensen/DS3232RTC
#include <Time.h>             //http://playground.arduino.cc/Code/Time
#include <Wire.h>             //http://arduino.cc/en/Reference/Wire

#define WAKE_PIN 2
#define LED_PIN 7

void setup(void)
{
    pinMode(LED_PIN, OUTPUT);

    // RTC config:
    RTC.squareWave(SQWAVE_NONE);
    pinMode(WAKE_PIN, INPUT_PULLUP);
    attachInterrupt(INT0, wakeUp, FALLING);
    RTC.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 1);
    RTC.alarm(ALARM_2);
    RTC.alarmInterrupt(ALARM_2, true);
}

void loop(void)
{
  if(RTC.alarm(ALARM_2)){
    digitalWrite(LED_PIN, HIGH);
    delay(5000);
    digitalWrite(LED_PIN, LOW);
  }

}

void wakeUp (){
// no-op, just checking if the interrupt fired
}

Why doesn't this work if I set the interupt to "LOW", ie., attachInterrupt(INT0, wakeUp, LOW);?
The reason I ask is I'm trying to use an RTC to wake from low power mode, and I think this doesn't work with a 'falling' interrupt.

So when you use LOW, the LED doesn't blink at all? Have u tried detaching the interrupt in the ISR and re-attaching in the IF block, to prevent multiple firings while the pin is low? Do you have any idea how long the pin remains low before going high again? Perhaps the arduino is too slow to respond

Yes, with LOW the LED does not blink ever. I have tried detaching the ISR and reattaching it without success. However, I've determined that the problem I have been fighting the last hour was due to placing the ISR definition after the loop function - which isn't supposed to matter. I'll update to the latest IDE and see how much of my problem is due to using an old and buggy IDE :/

That page is incorrect, although it reflects what the datasheet says.
The processor can be woken from RISING/FALLING/CHANGE/LOW. I queried this with Atmel and got this response:

Commented by Manoraj Gnanadhas (Atmel)
2015-01-20 06:23:36 GMT
[Recipients: Nick Gammon]
Hello Nick,
Our design team has confirmed that “Note-3 mentioned under Table 10-1” is a datasheet bug. So you can use any type of interrupt (Rising edge/ Falling edge / Low level / Any logical change) to wake up from sleep mode. Sorry for the inconvenience caused.
Best Regards,
Manoraj Gnanadhas

This is mentioned on my page about interrupts.

Why does LOW hang the processor? The LOW interrupt is not an edge interrupt but a continuous one. Thus, while the signal is LOW the interrupt is being continually called, with only one processor instruction being executed after each call to the ISR (which itself takes around 5.125 µs). So, the ISR is not being interrupted, but effectively only one instruction of your code is being executed every 5.125 µs (probably about 1/40th of the usual speed).

and see how much of my problem is due to using an old and buggy IDE

It's nothing to do with the IDE. Change to a FALLING interrupt and your problems should go away. You may also want to clear the interrupt flag (as documented on my page) in case the interrupt event has already happened before you go to sleep. Specifically:
EIFR = bit (INTF0);  // clear flag for interrupt 0

Thanks Nick. I have managed to get a cut-down excerpt of your data logger code working, using the WDT interrupt. I'm going to need to study this further - I have a few different sources like yours that I can get running as-is, but any modifications I try break them quickly! Clearly more study on my part is needed.


text:
Optocouplers for Arduino DCC decoder - Explain?
I am trying to make an Arduino circuit as outlined here.

This is for connecting an Arduino input to a DCC system. DCC is a command control system for model railways that uses the same two wires for power and data (there's a wikipedia article that explains it better than I can)
I'm wondering what the optocoupler has more than 4 pins for? I'm new to this and I understand the purpose of the optocoupler but I am confused as to how this particular one works. It is a 6N136 optocoupler. I don't understand why it has the extra pins compared to 4 pin optocouplers, and I don't understand how it would read the polarity of the signal. DCC sends commands using polarity as I understand it, so I know I need to read the polarity, but how does the optocoupler do it here?
I have a very limited knowledge of electronics right now so pardon anything stupid I said :P

I also built this circuit but sometimes my R1 1K resistor gets hot and nothing works. I have a dcc Roco Multim.10765 on the dcc side. I can't find what causes, you have an idea?

That specific chip (the 6N137) uses a more efficient IC detector rather than a simple transistor junction.  It also has an "enable" pin that allows it to be turned on or off.  Consequently it needs a power supply to run it. That all means extra pins.
This design allows for higher speed communication (it's a 10Mbaud chip) with less leakage when compared to a traditional design.
The pin VE (pin 7) needs to be pulled up to make the chip work (the job of R2) and the output is pulled high (it's open drain) by R3.
The optocoupler will be on with one polarity and off with the other. It's as simple as that. The diode D1 protects the LED in the optocoupler from the reverse voltages.

Out of curiosity, why does a diode need to be protected by a diode? (LED = Light Emitting Diode).

Reverse voltages on fragile optocoupler LEDs can break them, so by providing a low resistance path to cut out the reverse voltage you stop the led from being damaged.

So if I'm understanding this right, if I run AC current through there, then whenever it's in the reverse polarity of the LED, it will read as off because the LED inside will be off since its a diode?

Pretty much, yes. Except it's open drain, so it will be LOW when it is on.


text:
Use Adafruit Colorsensor to distinguish between green and red
I am using the Adafruit TCS34725 to sense color. I have used the Colorview code example to set it up to sense all colors, works great. The thing I want is for it to tell me if it is seeing either green or red, I don't care about the other colors.
Can anyone suggest what I can do?

if(r>200&&g<200&&b<200){println("RED!");}else if(r<200&&g>200&&b<200){println("GREEN!");}  ?

Okay, it seems you have 16-bit values, but don't make it too hard. As long as there is way more red as green/blue, you can say it's red.

Based on what I could find, you will have to calibrate the sensor to recognize these colours. First, run the Colourview code. Take down the raw RGB and CLEAR values obtained for an object you consider green and another you consider red. Find out if these values are consistent, each time you power down the sensor and turn it on again. If they aren't, record how much dead zone there is i.e. the maximum difference in readings (between resets) that you get for the same colour. Then using the values you get, try this code:
#include <Wire.h>
#include "Adafruit_TCS34725.h"

#define MAX_OFFSET 50  // the maximum diff you found between readings

typedef struct {  // struct to hold raw color data
   uint16_t red;
   uint16_t green;
   uint16_t blue;
   uint16_t clear;
} Color;

Color my_red = {3344, 3333, 23444, 3333}; //here you enter your minimum recorded values for red in the order of the struct members above
Color my_green = {22222, 4444, 5555, 3333}; //the same for green

void setup() {
  Serial.begin(9600);
  Serial.println("Color View Test!");

  if (tcs.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1); // halt!
  }
}

void loop() {
  uint16_t clear, red, green, blue;

  tcs.setInterrupt(false);      // turn on LED

  delay(60);  // takes 50ms to read

  tcs.getRawData(&red, &green, &blue, &clear);

  tcs.setInterrupt(true);  // turn off LED
  if (compare_colour(&my_red, red, green, blue, clear)){
      Serial.println("I see red.");
  }
  else if (compare_colour(&my_green, red, green, blue, clear)){
      Serial.println("I see green.");
  }
}

boolean compare_color(Color * std, uint16_t r, uint16_t g, uint16_t b, uint16_c){
if ((r - std.red <= MAX_OFFSET) && (r - std.red >= 0) &&
      (g - std.green <= MAX_OFFSET) && (g - std.green >= 0) &&
      (b - std.blue <= MAX_OFFSET) && (b - std.blue >= 0) &&
      (c - std.clear <= MAX_OFFSET) && (c - std.clear >= 0))
  {
      return true;
  }
  return false;
}

You can use this code directly after you have gotten the sensor readings for red and green objects.

Where should I substitute it? Not really sure where I should put this

Replace the colorview setup() and loop() with mine. Also copy all the extra stuff in my code (before my setup()), into the colorview code, at the same position. In the colorview code, get rid of any code at the top, concerning the RGB LEDs since you won't be using them (like the #define green_pin and so on), though this really isnt necessary. Make sure to get rid of the gammaTable created at the top though, to save memory.

I appreciate your time and answers, I have tried this with no luck.... I guess I am doing something wrong. Could you insert and replace the necessary parts of code so that I can see if this will work as I need it to?

@DanWilkes Ok. First tell me...have you gotten the readings for a red and a green object? Using the original Colorview code?

I have edited the code. You can use it as is. Only after you have gotten the the readings though. I cant tell you the values the sensor will return for a red/green object. You must run the colorview code (no need for the RGB LEDs) and take at least 10 separate readings and then select the minimum for each colour and the also obtain the maximum difference between the maximum and minimum readings for any colour and set the MAX_OFFSET variable to this difference.


text:
Reverse the order of a hex string
I'm printing an "unsigned long" value to HEX via:
println(cardCode, HEX);

The value that I'm getting is: 69fb879d
I need it to be reversed as: 9d87fb69
I populate cardCode via the code:
for (i=1;i<bitCount;i++)
{
  cardCode <<=1;
  cardCode |= databits[i];
}

going into this my bitCount value is 32, so basically I'm populating cardCode based on 32 bits from the variable databits which is of type unsigned char.
I am absolutely crap at bitwise conversions (bit-shifting, etc.), is there a simple way to do this reversal?  Is this even enough information to go on?

What exactly is in databits?

Your issue seems to be byte order (big endian) and not bit order. The simplest solution to byte order swap is to use the builtin functions provided by the compiler (AVR GCC).
unsigned long cardCode;
...
Serial.print(__builtin_bswap32(cardCode), HEX);

There are two compiler builtin functions for byte order swap. One for 16-bit data and one for 32-bit data.
uint16_t __builtin_bswap16(uint16_t);
uint32_t __builtin_bswap32(uint32_t);

AVR MCUs are little endian (least significant byte first in memory). There are many devices that use big endian (most significant byte first). This is also known as network order. There are a set of functions/macros to help write portable code, especially device drivers.
#include <arpa/inet.h>
uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);

These are used to map data from host to network byte order and reverse. They are defined as byte swap functions for hosts with little endian byte order. Unfortunately they are not available in the GCC AVR library but easy to define.
#define htonl(x) __builtin_bswap32((uint32_t) (x))
...

Cheers!

The title of this question is "Reverse the order of a hex string" but it was actually about reversing byte order in an unsigned long int.
Here is an answer for reverse the order of a string (null terminated vector of char).
There is a standard function for that in the C string function library.
char* strrev(char* s);

Cheers!

Sorry, misleading question title. It was about reversing the byte order of a value that became a hex string, and not reversing the string itself. Thanks

No problem! I just wanted to add this alternative answer for googlers. It also strengthens the original answer somewhat.


text:
Design Dilema -- What hardware?
I'm trying to build a smart thermostat for a particular application. I have the following design criteria and goals for the system:

Must be able to set up and monitor the device from either a mobile
phone or local network device.
No go on Ethernet or other hardwired connection, except for initial setup.  This must be a wireless solution. I'm presuming WiFi is best.
Needs a clock, an on time and an off time setting.
The system does a system time verification check once daily.
Needs a temperature input.
Needs to run an existing heater system (24v) thru a relay.
120v AC power (battery backup not required.)
Needs to be "hidden" in existing wall as much as possible.  (i.e. small & compact)  My intent is to hide the unit behind a double wide electrical duplex dead panel. (i.e. 4" x 4" nominal access thru drywall)

Here's a visual of my design intent package:
As I review a number of different hardware controller devices, I can see some issues.  I am very familiar with the Intel Edison, and I know exactly how to do this project there, including using the controller as a stand alone web host. (The Edison uses Yocto Linux to create a node.js server using http module.)  I was hoping to save a few $$ on hardware using an alternative controller but not sure that will work.  I've been wading thru the code for both the Photon and generic Arduino devices, and I'm getting the impression that I may need a custom server / api tool for a web page interface.  Its not clear that those hardware choices will support an interactive web page, particularly for easy user data update via browser Submit button.  That's not a big problem, I'm a freelance software developer, handy in C/C++/Java, PHP and JavaScript. And as for the Raspberry Pi, I have no experience but the pricing on some of their boards is below $15.
Here are my questions:

Has anybody used an Arduino board to host an interactive web page, including user input via Submit / Form ?  (Can I declare a local network static IP address for an Arduino?)
Has anybody used an Particle Photon board to host an interactive web page, including user input via Submit / Form? (It looks like declaring a local network static IP address on a Photon is anything but easy...)
Has anybody written an API Restful server for their Arduino, with both get and put functionality?  (I'm thinking PHP, or node.js makes the most sense for me.)  I know if I have to use Dynamic IP addressing to the controller, that I can always make an API system work for the system.
Other comments?

Why not ESP8266?

@ignaciovazquezabrams That board appears to be awesome as a WiFi interface, but doesn't appear to have the processing power to read analog input and function as a server and overall stand alone controller.  Its very well priced to provide WiFi service to another device.

Then you haven't really looked at it.

@IgnacioVazquez-Abrams  Very right you are.  I'm looking at the documentation at a number of places and its not at all clear this board will be fully functional for this application. 1- instructables 2 - nurdspace 3 - Sparkfun  Can you recommend better documentation that makes your suggestion and the device capabilities really clear.  I'm really liking the pricing of this thing!  Thx.

@IgnacioVazquez-Abrams   ha... here is a better reference at Makezine  In fact, make this recommendation an answer, will you?

What are your priorities when it comes to HW cost vs. ease of implementation? An Rpi is clearly over-dimensioned for the task, but will be up and running in an afternoon or so with HTTP, PHP, node.js & c. An Arduino-like board can be made for US$3-5, but significantly more development may be required; there's no PHP or other fancy stuff. HTTP server is available, NTP I'm not sure. WiFi via external component...

FYI; Using a relay isn't ideal if you have an modulating furnace.

Personally, since you want to build just one prototype and not many, I suggest you to use a raspberry PI. You can use it almost the same as the edison (you won't use yocto but just a debian derivative; the packages and applications, however, are almost the same). It costs about half the price of an edison (or even less if you get the cheapest one - you don't need the ethernet port, do you?) and you will have a lot of computing power. If you want to lose time, you can use an ESP in standalone version. And BTW, you can use a digital temp. sensor (it's easier to use and with less components).

Has anybody used an Arduino board to host an interactive web page, including user input via Submit / Form ?

I have a Tiny Web Server for the Arduino. It is designed to be light-weight on RAM. It supports GET/POST/Cookies for interacting with web forms.

Example code and more information on the linked page above.

(Can I declare a local network static IP address for an Arduino?)

Yes.

Other comments?

You could use NRF24L01 modules for short-range communication of wireless information. I have example code and schematics. My tests seemed to indicate 20m range was achievable.

Have you looked at the Adafruit Huzzah boards? It's small, inexpensive ($10), comes with wireless capability and a 10-bit ADC for a temperature sensor. If you'll have access to the Internet, then you could use NTP to get time.

I've been looking at it.  That is exactly the same suggestion as was made by @IgnacioVazquez-Abrams to look at the ESP8266.  In fact I've been studying up on those for the past two hours.  The Adafruit Huzzah and the NodeMCU are two implementations that have got my interest.  Both of those boards expand the pinouts, as well as add 5v -> 3.3v regulation.  I've been reading up the awesome E-book on the ESP8266 from Neil Kolban  Clearly this chip makes a lot of sense for me, if I can get the desired I/O to fit and function in existing memory.

From the looks of your specs for the project a '328 Arduino would have more than enough flash (32K) and RAM (2K) to run your application – based on having built similar projects using an Uno. You've got the ADC as well as several GPIO pins. What I can't tell from Adafruit's page and the data sheet is if you get any flash, but it is capable of addressing up to 16 MB and that's way more than you need.

Sounds great.  I just ordered a few boards and supporting supplies from Ebay.  I ordered a few xtra sets, thought this would make a good meetup project for the folks locally.  The board was $5.36 / ea, Wow.  Not sure what you mean about the 328 Arduino.  I'm hoping to use a virgin ESP8266 board.  From what I can see that board has 512KB flash memory.  I only need one analog input and one general I/O output.  Not sure about the web stuff yet.. For as little as this cost I'm going to try and see what happens.  I know I can always fall back and use the Intel Edison.


text:
Multiple I2C Devices connected parallel
I have two Lidar Lites, connected to one APM. I have no issue with getting data from one of them, i use the code below
#include <I2C.h>
#define    LIDARLite_ADDRESS   0x62          // Default I2C Address of LIDAR-Lite.
#define    RegisterMeasure     0x00          // Register to write to initiate ranging.
#define    MeasureValue        0x04          // Value to initiate ranging.
#define    RegisterHighLowB    0x8f          // Register to get both High and Low bytes in 1 call.

void setup(){
  Serial.begin(9600); //Opens serial connection at 9600bps.
  I2c.begin(); // Opens & joins the irc bus as master
  delay(100); // Waits to make sure everything is powered up before    sending or receiving data
  I2c.timeOut(50); // Sets a timeout to ensure no locking up of sketch if I2C communication fails
}

void loop(){
 // Write 0x04 to register 0x00
  uint8_t nackack = 100; // Setup variable to hold ACK/NACK resopnses
  while (nackack != 0){ // While NACK keep going (i.e. continue     polling until sucess message (ACK) is received )
    nackack = I2c.write(LIDARLite_ADDRESS,RegisterMeasure, MeasureValue); // Write 0x04 to 0x00
    delay(1); // Wait 1 ms to prevent overpolling
  }

  byte distanceArray[2]; // array to store distance bytes from read function

  // Read 2byte distance from register 0x8f
  nackack = 100; // Setup variable to hold ACK/NACK resopnses
  while (nackack != 0){ // While NACK keep going (i.e. continue polling until sucess message (ACK) is received )
    nackack = I2c.read(LIDARLite_ADDRESS,RegisterHighLowB, 2, distanceArray); // Read 2 Bytes from LIDAR-Lite Address and store in    array
   delay(1); // Wait 1 ms to prevent overpolling
  }
  int distance = (distanceArray[0] << 8) + distanceArray[1];  // Shift high byte [0] 8 to the left and add low byte [1] to create 16-bit int

  // Print Distance
  Serial.println(distance);
}

i can get the distance fine, now have two connected, as follows

So my noob question is how to i get data from the 2, my guess is the wiring is ok.
I am using the code from https://github.com/PulsedLight3D/LIDARLite_v2_Arduino_Library
any help would be appreciated. thanks.

Did you give them distinct addresses?

if i run a I2C scanner it only shows one address and one device 0x62 , i can change the address, but it doesn't help as i still don't know whats the address of the 2nd one or if i have access to it.

Then the answer is "no".

The change address example sketch looks like giving each LIDAR an individual address is easy...

Diagram Multi-sensor PWR_EN Wiring shows each sensor's PWR_EN connected to independent digital outputs, so you should be able to call the changeAddressMultisensor function in your setup(). See Change I2C Address for Single Sensor You may have to use CTRL+F (find on page) "Change I2C Address for Single Sensor" as the href doesn't seem to work right on chrome or firefox.

There is some excellent instructions in the source code; https://github.com/PulsedLight3D/LIDARLite_v2_Arduino_Library/blob/master/LIDARLite/LIDARLite.cpp#L585

Connect one at a time and run the change address sketch mentioned by Yeti.
Naturally change each one (one at a time) to different addresses (ex. 0x62, 0x64, 0x66).

i still don't know whats the address of the 2nd one

The address is what you change it to.
Then connect them all back up again and run the I2C scanner. You should see all 3 addresses.

documents state that address changes will be gone when i power it off

If that is true, save the address for each module in EEPROM. Then use that code to change the module address in setup.

See the address in the code you posted?
#define    LIDARLite_ADDRESS   0x62          // Default I2C Address of LIDAR-Lite.

If you don't want to save the address in EEPROM just upload three versions of the sketch with a different address in each one. Note that the address must be even (eg. 0x62, 0x64, 0x66).
But it would be very simple just to read from EEPROM in setup and keep the address in a variable rather than a #define.

documents state that address changes will be gone when i power it off.

Then turn off two lidars with transistors, program the first one, turn on the second one, program it, then turn the last one on. That way there are no address conflicts while programming it as all the addresses are different while programming any of them.