text:
Individual control of multiple RGB leds
I'm trying to control several RGB leds individually. So far I've been able to control multiple RGB leds using only 3 PWM outputs using NPN transistors as shown here (pic below).

I would like to control each led individually in order to display different colors in each led. If I used the Arduino Mega, which has 12 PWM pins I could only control 4 different groups of leds using the approach mentioned above. It would be nice to be able to control them using the Arduino Uno or other boards with less PWM pins.
What would be a good solution for this? I've been taking a look to shift registers using ShiftPWM and solutions like the TLC5940 but I haven't got enough experience to tell which way would work better.

I do wish people would draw proper schematics. I can't work out head nor tail what is going on in that circuit. Use the TLC59116 - it's the best LED driving chip ever.

simply because of availability, try the software solution first, then try the hardware one.

@guardabrazo If by good you mean cheap solution to control several RGB lights. Then you can use a 4017 decade counter to multiplex the RGB lights so control several RGB lights. with a single 4017 is about 20 times cheapper than the TLC59116 costing about 17 cents. With a few 4017's you can control more than 100 RGB lights. This would only use a on the Arduino.(including a few PWM pins).

"Digital led strips" have individually colorable LED's. Thuis would be much more favourable as a tricky solution.

Here is a 1/2 software 1/2 hardware solution:
You actually have 6 pwm pins (from the silk screen notation in your picture).  So you can control 2 RGB LEDs independently.  If you added 4 more transistors that are used to gate the common 5v going to each of the 4 RGB LEDs you could control them in pairs.  That is, you could turn on 2 independently controlled RGB LEDs and let the 6 PWM outputs control the brightness and color of each of the 2 for, say, 100ms.  Then you could turn those off and turn on the other 2 independently controlled RGB LEDs for 100ms.  During the switch, you would change the PWMs for the 2nd set of RGB LEDs.  The draw back to this approach?  You may start noticing the LEDs flickering.  You may have to adjust the rate which you switch between the two pairs of LEDs.  And, of course, it may not work as you expect it to.
Totally different approach:
You can use programmable RGB LEDs:

And use this Arduino software library. These types of RGB LEDs have the PWM build in.  The Arduino sends out serial data to the first LED which strips off its RGB data.  Then sends the data to the next RGB LED which does the same.  So you can control many RGB LEDs using a single pin on your Arduino.

There is an alternative that gives you more PWM pins when using an Arduino Uno. You need a 74HC595 shift register which has eight additional output pins. By default, these pins are not PWM capable, however, with a library that I have developed they are.
You can then easily replace your analogWrite calls with something like that sr.set(i, val);. The parameter i indicates with shift register pin you want to update and val is a PWM value (from 0 to 255).


text:
Help avoiding floating point math
I'm using a Texas Instruments DRV2605 haptic controller in my project to drive a LRA vibration motor. I would like to calculate the LRA rated voltage during run time using the formula below as provided in the datasheet:

I'm successfully calculating the rated voltage, but the calculation requires floating point calculations and I would like to avoid that because I'm low on available flash space on my ATTiny85 micro controller. Here is how I'm currently calculating the rated voltage value:
uint8_t LRA_closed_loop_rated_voltage( uint16_t voltage ) {
   float RatedVoltage;
   uint16_t SampleTime = 300;
   uint16_t frequency = 175;

   RatedVoltage = ( (float) voltage ) * sqrt( 1 - ( ( 4 * SampleTime + 300 ) * 0.000001 ) * frequency );
   RatedVoltage = ( RatedVoltage * 255 ) / 5300;

   return RatedVoltage;
}

The function above is just a simplified version showing the calculation and the SampleTime and frequency variables are set to their defaults values here. The voltage argument is the actuator's rated voltage in millivolt.
EDIT: Even though SampleTime and frequency have fixed values in the function above, their values will be determined by reading the relevant registers in the final implementation. SampleTime may have one of the following values: 150, 200, 250, 300 and the frequency will depend on the manufacturers specifications for the actuator.
It was easy to overcome the floating point issue on the other calculations by simply scaling up the values by 1000 (fixed point arithmetic):

ODClamp = ( Vpeak * 255) / 5.6 /* Vpeak in volts */

TO:

ODClamp = ( Vpeak * 255) / 5600 /* Vpeak in millivolts */

How can I do the calculation in question without having to use floating point?

The only difficulty seems to be evaluating the function f(x) = sqrt(1 − x). There are many ways to compute fixed-point approximations of this function, and there is no universal solution. The “right” approximation for your application depends on: 1) what is the possible range for x? 2) what level of accuracy do you require?

Calculate values off-line and generate a table in PROGMEM. See the Adafruit examples.

Or use a polynomial approximation. If sampleTime and frequency are close to their default values, a Taylor expansion around those values might be good enough. E.g. at order 2 you have f(x) ≈ 0.99801 − x (0.47861 + x 0.19736).

As I said in my comment, it is all about computing an approximation of
sqrt(1-x). Assuming the typical resonance frequency is between 175
and 235 Hz, then we have

(4 × 150 µs + 300 µs) 175 Hz ≤ x ≤ (4 × 300 µs + 300 µs) 235 Hz

i.e.

0.1575 ≤ x ≤ 0.3525

This range is small enough to try a simple polynomial approximation. A
linear approximation is just a bit too crude for 8 bit resolution.
Playing with quadratic polynomials, I found this approximation which is
good to 3.1e-5 in the relevant range:

√(1−x) ≈ 0.9983795 − x (0.480515 + x 0.1955)

This can be easily implemented in fixed point by scaling everything by a
factor 216 = 65536. One has to take care that any
product of two such fixed point numbers must be computed in
32 bits, and the result subsequently divided by 65536. Which gives
the following implementation:
/*
 * Compute a fixed point approximation of f(x) = sqrt(1-x).
 * Valid for x in [.1575, .3525].
 * Argument and result scaled by 2^16.
 */
uint16_t f(uint16_t x)
{
    return 65430 - x * (31491 + x * 12812UL / 65536) / 65536;
}

source: Stack Exchange

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

sort: votes


text:
Arduino box stops working: Reading RFID tag and sending data over network
This is a simple Arduino program which reads RFID tag and sends the data over a network (lora).
The program works fine in as i run it, the arduino reads RFID and sends it over the network (lora)
but
after a few hours it stops responding it neither reads nor sends the data over network (lora network).
I am very new to arduino and have no idea what causes the box to stop responding, kindly help.
When i restart the boxes or upload the code to it again, it starts behaving normally for a few hours and then goes back to not responding.
    /*
   Typical pin layout used:
   -----------------------------------------------------------------------------------------
               MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
               Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
   Signal      Pin          Pin           Pin       Pin        Pin              Pin
   -----------------------------------------------------------------------------------------
   RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
   SPI SS      SDA(SS)      10            53        D10        10               10
   SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
   SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
   SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
   Red LED                  A0
   Green LED                A2
   Blue LED                 A3
*/
/***********************************************************************************************/
//#include <SPI.h>
#include <MFRC522.h>
//#include <HID.h>

// Cooking API libraries
//#include <arduinoUtils.h>
//#include <arduinoUART.h>
//#include <arduinoMultiprotocol.h>
#include <arduinoLoRaWAN.h>

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above
#define MAX             10         // Maximum Buffer size
#undef Debugg
/******** RFID Reader initialization**********************************************/
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
//char rfid_old[MAX];
byte *buffer;

/******************************LoRa Initialization********************************/
// Pin definition for LoRaWAN module error LED:
const int error_led =  7;
//////////////////////////////////////////////
uint8_t socket = SOCKET0;
//////////////////////////////////////////////

// Device parameters for Back-End registration
////////////////////////////////////////////////////////////
char DEVICE_EUI[] = "0000000097E471E1"; // 0000000097E471E1 / 00000000518AD184
char DEVICE_ADDR[] = "97E471E1"; // 97E471E1 / 518AD184
char NWK_SESSION_KEY[] = "00EBB4C1FCDFF52878B1725CBDFF0BA1"; // Configured for TTN
char APP_SESSION_KEY[] = "4EDC3AB4F79C565685109ECD4AF4604C"; // Configured for TTN
char APP_KEY[] = "70B3D57ED0000300"; //APP_EUI
////////////////////////////////////////////////////////////
// Define port to use in Back-End: from 1 to 223
uint8_t PORT = 1;

// variable
uint8_t error;
uint32_t cFreq[] = { 867100000, 867300000, 867500000, 867700000, 867900000 };
char rfid_arr[MAX];
char stampleErrorChar[] = "4AD6A6A65784AEBA2B"; // this data is sent from the WService When Stample Error-> Error
/* *******************************START Initialize Indication LEDs******************************* */
int greenPin = 6;
int redPin = 8;

void setup()
{
  Serial.begin(57600);
  //LoRaWAN example - Send Unconfirmed packets (no ACK)
  pinMode(error_led, OUTPUT);
  digitalWrite(error_led, LOW);

  LoRaSetup();
  RfidSetup();
}

//-----------------------------------------------------------------------------
// Name.: RfidSetup
// Descr:
//
// In...:
// Out..:
// Ret..:
//-----------------------------------------------------------------------------
void RfidSetup()
{
  SPI.begin();                        // Init SPI bus
  mfrc522.PCD_Init();                 // Init MFRC522
  mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
}
void LoRaSetup()
{
  LoRaWAN.ON(socket);
  LoRaWAN.factoryReset();

  // Channel parameters
  for (uint8_t i = 3; i < 8; i++) {
    LoRaWAN.setChannelStatus(i, (char*)"on");
    LoRaWAN.setChannelFreq(i, cFreq[i - 3]);
  }
  for (uint8_t i = 0; i < 3; i++) {
    LoRaWAN.setChannelDutyCycle(i, 302);
  }

  for (uint8_t i = 3; i < 8; i++) {
    LoRaWAN.setChannelDutyCycle(i, 99);
  }

  LoRaWAN.setPower(5); // [N/A, 14, 11, 8, 5, 2] dBm
  LoRaWAN.setADR((char*)"off"); // Adaptive data rate
  LoRaWAN.setDataRate(5); // [250, 440, 980, 1760, 3125, 5470, 11000];
  LoRaWAN.setDeviceEUI(DEVICE_EUI);
  //showErrorResult((char*)"2. Set Device EUI ", LoRaWAN.getDeviceEUI());
  LoRaWAN.setAppEUI(APP_KEY);
  //showErrorResult((char*)"3. Set APP EUI ", LoRaWAN.getAppEUI());
  LoRaWAN.setDeviceAddr(DEVICE_ADDR);

  LoRaWAN.setNwkSessionKey(NWK_SESSION_KEY);

  LoRaWAN.setAppSessionKey(APP_SESSION_KEY);
  //showErrorResult((char*)"6. Set App Session Key ",error);
  LoRaWAN.setRetries(3);
  LoRaWAN.saveConfig();
  LoRaWAN.joinABP();
}

void loop()
{
  // Look for new cards
  if (! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  else
  {
     error = LoRaWAN.joinABP();
     if (error == 0)
     {
       char* UId = GetUid(mfrc522);
       if(UId != NULL)
       {
          BlinkGreen(500);
          delay(100);
          // Send it!
          error = LoRaWAN.sendUnconfirmed(PORT, UId);
          Serial.println(error);
          delay(100);
          if(error == 0)
          {
             Serial.println(LoRaWAN._dataReceived);
             BlinkGreen(1000);
          }
          else
          {
             BlinkRed(1000);
          }
        }
        delay(2000);
     }
  }
}

char* GetUid(MFRC522 mfrc522)
{
    // Optional: Dump data about the cards
    //mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
    buffer = mfrc522.uid.uidByte;

    for (int i = 0; i < mfrc522.uid.size; i++)
    {
      sprintf(&rfid_arr[i * 2], "%02X", mfrc522.uid.uidByte[i]);
    }
    mfrc522.PICC_HaltA(); //command the card into sleep mode
    return rfid_arr;
}

void BlinkGreen(int delayTime)
{
  digitalWrite(greenPin, HIGH);
  delay(delayTime);
  digitalWrite(greenPin, LOW);
}

void BlinkRed(int delayTime)
{
  digitalWrite(redPin, HIGH);
  delay(delayTime);
  digitalWrite(redPin, LOW);
}
void showErrorResult(char* errorMessage, uint8_t error)
{
  if(error == 0)
  {
    Serial.print(errorMessage);
    Serial.println("OK!");
  }
  else
  {
    Serial.print(errorMessage);
    Serial.print(" Error: ");
    Serial.println(error);
  }
}

A pure guess from your symptoms would be either a memory leak or a counter overflowing.  I'll look at the code and get back to you.

Is you Arduino overheating? can you start a second couple of hour run within minutes of the first?

@Matt,
thanks guys. But if rfid_arr size was an issue, wouldn't the box be giving problem the first time we use it? because it works for few hours before it goes into not responding state. The rfid tag data looks like below
AEA00622
DE1CD403

The bad news is I can't see that much wrong with your code.

You need to set the Red and Green pinModes().  You've set error, but then don't use it.  I'm guessing the green LED is a new feature.  similarly you could refactor the blink green and blink red functions into one and pass in the pin number.
Are you sure that the mfrc522.uid.size is always less than 5?  In GetUid() you assume that i*2 will fit into the buffer rfid_arr which is 10 bytes.  sprint() always attaches a null onto the end of what it rights to the buffer so this will overflow if you write elements 9 and 10.

I really doubt either of those are the problem you are looking for, so would it be possible to stick loads of Serial.println() statements in and see where abouts it is crashing?

Make sure you put Serial.flush() after each Serial.println() or the crash itself may truncate your serial output and leave you looking in the wrong place.

Reply, thanks guys. But if rfid_arr size was an issue, wouldn't the box be giving problem the first time we use it? because it works for few hours before it goes into not responding state. The rfid tag data looks like below
AEA00622
DE1CD403

Matt, I did not get you mate. I have not changed anything in the code and the issue is still there. What do you see is wrong? or more precisely what shall i change in the code?
The rfid data looks like DE1CD403
Thanks a lot for your coooperation

(I misread you comment, so...)
What is the length of the RFID data is it 4 bytes or 8 bytes?  Is mfrc522.uid.uidByte[i] an unsigned byte? if so your format string should be "%02hX".  Otherwise if the value of mfrc522.uid.uidByte[i] is 0xFF then you will end up with rfid_arr[i * 2] = "0xFFFFFFFF" which if its the last byte will extend the array by 6 characters.  So if the RFID length if 4 bytes its a data dependent error and if its 8 bytes then its just a question of time.

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


text:
Is it possible to hookup two ultrasonic sensors to one Arduino Uno unit?
I found a couple of projects using Ultrasonic Distance sensor with Arduino Uno. Is there a way to connect two or more sensors on the same Arduino Uno?

Yes there is. What have you tried? What have you had problems with?

Please help us help you by providing your code showing your efforts.

Well I actually I did not try it yet it's just that I had worries that it might not by feasible so I did not buy any hardware and made the bad decision to ask a question here without trying anything :)

It is possible. Just ping then one after another, or both at the same time.

Yes, it is certainly possible.  There are a few things you need to be aware of:
1)  The Arduino UNO is 5V by design.  Many sensors (not all, but many) are 3.3V devices.  So connecting them to a 5V pin could damage them.  Since you seem to be just starting out, I'd recommend sticking with 5V tolerant sensors.
2)  The Arduino UNO only has so many pins available....obviously.  Different sensors require different amount of pins to 'work'.  For example, a temperature sensor might work with the SPI interface.  Another sensor might require 8 pins.  So if you start running out of pins, you need to think about other challenges like using shift registers, multiplexers, etc.
3)  Don't be afraid to experiment.  I suggest buying a genuine Arduino UNO to support the project.  Maybe buy some cheap Chinese ones to experiment on...in case you fry on of those.
In theory, the sky's the limit when it comes to "how many".  In real life, if you start going over a handful, dozen, etc. then you might want to rethink your design.

You make some useful general points, but Stack Exchange is really about specifics - a specific question, and an answer which specifically addresses it.  Very little of what you have said applies to the actual question asked.

@ChrisStratton you have a point but I guess my question was also too broad

@ChrisStratton people come to Stack Exchange via searching or directly.  Looking for answers.  Sometimes the questions are broad like this one Sometimes they are very specific.  It seems that every day I see more and more examples of people scolding new users, beginners and amateurs.  Many times S.E. is the first response to a Google search.  Yet, when beginners ask, they are told to "Google it" and get down-voted and closed.  I understand that S.E. is about specific questions.  This question seemed specific enough for me. Google brings people here and they are punished, where should they go?

The problem isn't so much the question, as that you didn't answer it.  Very little in your response is even applicable to the actual question, vs some other ones not asked.

I guess I read the question as "is it possible".  My mistake.  But I still stand by my remarks.  Point is, many people come to S.E. looking for generic answers to their generic questions and, apparently, S.E. isn't a place for that.


text:
Serial Communication Between 3 Arduinos Doesn't Work (Daisy-Chain)
In my project, I have to send a string from one arduino to a second arduino, and make it send the same string to a third arduino. I used UART and SoftwareSerial library, and connected the arduinos like that:
In all the arduinos:
Pin 10 - RX port, pin 11 - TX port

Arduino 1 pin 11    ---->  Arduino 2 pin 10
Arduino 2 pin 11    ---->  Arduino 3 pin 10
Arduino 3             ---->  PC (by hardware Serial)
By theory, Arduino 1 sends string "CA" to arduino 2, which resends that same string to arduino 3, that prints it back on Serial.
The problem is that I get the string "C�" instead of "CA" (that weird "C�" is equal to "067 255" on ASCII).
Does anyone knows why it happens? Maybe there's something wrong with my code?
Here's the code for all the three Arduinos:
Arduino No. 1:
#include <SoftwareSerial.h>

#define ADDR "CA"
SoftwareSerial tiny(10, 11); //TBD

void setup() {
  Serial.begin(9600); //debug only
  tiny.begin(9600);
  delay(2000);

  tiny.write(ADDR);
}

void loop() {
  //nothing here
}

Arduino No. 2:
#include <SoftwareSerial.h>
SoftwareSerial tiny(10, 11); //TBD
void setup() {
  Serial.begin(9600); //debug only
  tiny.begin(9600);
}
void loop() {
  if(tiny.available() > 0) {
    tiny.write(tiny.read());
  }
}

Arduino No. 3:
#include <SoftwareSerial.h>
SoftwareSerial tiny(10, 11); //TBD
void setup() {
  Serial.begin(9600); //debug only
  tiny.begin(9600);
}
void loop() {
  if(tiny.available() > 0) {
    Serial.write(tiny.read());
  }
}

Any idea on what went wrong?

Where are your ground connections? I don't see them there.

Where is it being modified / becoming corrupt ?  Have you printed to debug serial on Arduino 2 to see if it is receiving corrupt data, or if the data is being corrupted on the 2-> leg ?  Also have you swapped them around (Arduino 2 becomes Arduino 3 etc) ?

@Majenko They are all connected to the PC, so their grounds are connected (nevertheless, I tried to connect their grounds together and it didn't help).

@KennetRunner It is being corrupted when it gets to Arduino 2 (gives same results). I tried to swap arduino 2 and 3 but it didn't help.

Connecting the grounds through the USB is not adequate. You need a direct connection between all the boards' grounds.

SoftwareSerial is appallingly bad. It barely works at the best of times. Try sending 'C' then delaying, then sending 'A'.

@Ido Daniel - I'd also remove Arduino 3 from the picture until you get 1 -> 2 working correctly, then introduce it back in...

@KennetRunner Actually, given that Arduino 2 is merely a proxy, I'd remove Arduino 2 until 1 -> 3 directly works correctly...

@John Burger Given thatArduino 2 is where the first evidence of corruption occurs I'd start there. Either way will work though...

Arduino #2 should have two SoftwareSerial instances, one to listen to Arduino #1 and another one to talk to Arduino #3:
// In Arduino #2
SoftwareSerial tiny1(10, 11); // Listen to Arduino #1 on pin 10
SoftwareSerial tiny2(8, 9);   // Talk to Arduino #3 on pin 9

You may not need to wire unused signals (11 and 8).
There is an example here : https://www.arduino.cc/en/Tutorial/TwoPortReceive
Note that what you are trying to do is a bus. Serial in Arduino is RS232 based and that is not a bus but a point to point protocol. You should consider using I²C or SPI.


text:
Arduino mini pro as ISP for Atmega329P-PU serial monitor failing
After trying a lot of tutorials and manuals around the web including at least 20 solutions here on StackExchange, I don't know what to try anymore.
My goal is to write a message in the serial monitor window of the Arduino IDE from my ATMEGA328P-PU.

I have written the Arduino bootloader (tried 8 and 16MHz) to the ATMEGA and I use a 'blink' sketch as follows:
void setup()  {
 Serial.begin(9600);
 delay(100);
 pinMode(9, OUTPUT);
}

void loop()
{
 digitalWrite(9, HIGH);
 Serial.print("high");
 delay(1000);
 digitalWrite(9, LOW);
 Serial.print("low");
 delay(1000);
}

The blinking works fine, the timing looks good, not overly fast or slow.
I connect PIN3 (PCINT17, PD1, TXD) directly to the RX on the Arduino (lower red wire) and the serial monitor responds by returning nonsense like ����������.
I have checked the baud rate. I have also tested with all other baud rates in combination with and without 8Mhz and 16MHz.
I have tested the entire setup with another ATMEGA328P-PU and using an entirely other PC. Same results.
It is not possible to upload a sketch while leaving the TXD -> RX connected, so I disconnect this cable when I upload a sketch. I have also tested with only power and TXD -> RX connected.
I have also tried a few types of resistor between the TXD and RX, one of many tutorials recommended this.
This is what I am trying:
http://www.instructables.com/id/Attiny-serial-monitor-using-arduino-walkthrough/
And this is my boards.txt:
##############################################################

atmega328bb.name=ATmega328 (8 MHz internal clock)

atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05

atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=16000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard

atmega328bb.bootloader.tool=arduino:avrdude
atmega328bb.upload.tool=arduino:avrdude

The problem is most likely that big white component. Yes, that one. The breadboard. It has huge parasitic capacitance and will be affecting the frequency of your crystal oscillations, thus skewing your baud rate enough to break communication.

I have tried without external oscillator..

So you have arduino pro mini as ISP and you've connected TX pin from mega328p to pro mini RX input (which is also connected to USB->Serial TX pin). And you wonder why it returns junk data from pro mini Tx pin?

Speaking of capacitance, I don't see any decoupling on that ATMega328 chip...

yes I wonder why it returns this, that is why I post a question here.

Well, you have Arduino ISP on that arduino mini pro and if you connect output of bare chip to input of that arduino then Arduino ISP is confused and sends (possibly) some responses to its RXO pin (connected to TX Input on USB-Serial board).

Is ArduinoISP not supposed to forward this information to the Arduino IDE? How else would I read serial messages from the bare chip?

I don't think so. Even if it does, it's possibly running at much higher baud rate. And if there are no resistors on that USB-Serial you have shorted two outputs.

As you can see at image from linked instructables, they've connected TX pin from Tiny to TX pin on UNO through 220R resistor. This is extremely lousy idea as UNO and Tiny are both driving TX pins.
On the other side you've connected TX Output pin from Target CPU into RX Input of the Arduino ISP (pro mini). Arduino ISP returns some error responses from its TXO pin directly into the monitor. And it's at different speed I suppose, as default baud rate is 19200 in Arduino ISP sketch.
Also using internal 8MHz oscillator and: atmega328bb.build.f_cpu=16000000L means you are running at half speed as compiler and everything else expects. All speeds will be at half rate. Delays twice as long and so on.
Anyway, you can disconnect your USB to Serial converter and connect it directly to the target CPU. Or use two of them. Or just upload bootloader and get rid of ISP.

great, just wiring the FTDI to the ATMEGA gives me normal serial monitor response. it does leave me with another challenge, uploading sketches does not work.

The thing is that you have 2 ATmegas for 1 uploader. You can't really remove the ATmega on the Pro Mini so I suggest removing the ATmega of an UNO and using the UNO without the ATmega to program your seperate ATmega. Tx to Rx and vice versa. 16MHz will work.

No change of boards is needed, it is only necessary to hold the on-board ATmega in reset, and bring the raw DTR or RTS line over to a copy of the reset circuit for the target one.  However, if loading anything that uses SPI or toggles those pins it would generally be good to make sure the ISP (SPI) lines are disconnected between the two, to make sure the slave doesn't accidentally deprogram the on-board ATmega (seen that happen!)

So how's my anwser?

Not very good, as you are proposing that an unnecessary purchase of different hardware be made.


text:
Errors in code, LM35 temperature logging to web server
trying to experiment with Wemos D1 and LM35. Need to have temperature reading on the ESP IP. Found the following project to be exactly matching my requirements but I am having certain errors in it. Since, I am not that expert with C programming, hence I am unable to resolve the issues and the website admins are also not replying. If you can please help get this program work or point me to some other source. (There are a lot which involve thingspeak.com but I do not want that. A simple WiFi connection to ESP through mobile and get the data on the esp server IP page which is 192.168.4.1 in Wemos.)
Here is the link,
http://blog.circuits4you.com/2016/03/web-server-data-logger.html
First error I get is "temp is not declared". If I declare temp as int then the compiler gives error on spnprintf statement saying "Invalid conversion from int to char*". Tried to read snprintf reference but could not understand the error. Perhaps there will be more errors after this line too. Kindly help.

Read into this. Your code gets an error and it literally describes what's happening: look into it. I'm also voting to close this question because it does not relate to Arduino, it relates to C++ and programming in general.

It's expecting buffer to write all that data: char temp[400];. The snprintf writes at most 399 characters and termination character '\0'. And nobody cares that it generates ugly html:
  char temp[400];
  snprintf ( temp, 400,
""
  ""
    "<meta http-equiv='refresh' content='5'/>"
    "<title>Circuits4You.com Temperature Monitoring Server Demo</title>"
    ""
  ""
  ""
    "
Temperature: %04d
"
  ""
"", analog
  );

It seems like you haven't declared the variable 'temp' from the line
server.send ( 200, "text/html", temp );

It should work fine if you declare it.

I already said that I declared temp as int later on. Then I am getting the second error on snprintf.

You can't declare variables "later on". They have to be declared before they are used.

by later on i meant after executing the program first time...it gave the variable declaration error so I declared it. Later on did not mean later on in the program :D

and is it working now?


text:
AVR (Arduino Uno) Serial.print and Serial.println only printing 1 or 2 chars
I first used the Arduino IDE but now I'm using PlatformIO which is awesome. But I have some big trouble with Serial.print() and Serial.println(). To show this error I have the following example code:
#include <avr/io.h>
#include <util/delay.h>
#include "Arduino.h"
#include "main.h"

int main(int argc, char const *argv[]) {
  Serial.begin(9600);

  section5ex34();

  return 0;
}

void section5ex34() {
  // Initialization
  DDRC = 0b00000100; // Port C2 as output and the rest (including Port C3) as input. (Port C2 is used for a led that indicates when en bit is being read)

  uint8_t b = 0b00000000;

  // here the code reads bits from PORTC3
  for (int i = 0; i < 8; i++) {
    _delay_ms(1000);
    PORTC |= _BV(PORTC2); // Make Port C2 high (indicates a bit will be read)

    if ((PINC & (0b1 << 3)) != 0) {
      b |= (1 << i);
    }

    _delay_ms(100); // Wait for the user to prepare the next bit (because this is now done by hand)
    PORTC &= ~_BV(PORTC2); // Then make Port C2 low
  }

  Serial.println(b, HEX);
}

When I have the code like this, it prints the right Hexadecimal value corresponding with the 8 read bits.
When I add Serial.println("test"); after the print, it doesn't print that.
Or when I change Serial.println(b, HEX); to Serial.println(b, BIN); it prints 11.
When I replace those 2 prints with Serial.println("Hi test test."); it prints Hi, so it seems like it can only print 2 characters.
When I add Serial.println("Hello world . hello . hi"); four times after Serial.begin(9600);, it prints Hello world . h and nothing more. So here it seems like it can print more than 2 characters, but not all. If I wait a few seconds it adds ello to this, so it says Hello world . hello.
In the initial code, when I replace the if-statement with
if ((PINC & (0b1 << 3)) != 0) {
  b |= (1 << i);
  Serial.println("1");
} else {
  Serial.println("0");
}

and when the input is connected to 5v (so high) it prints a 1 once and nothing else, not even a hexadecimal value when the reading is finished.
This problem drives me crazy.
I have an Arduino Uno and use a baudrate of 9600 , 8,N,1.
I hope someone can help me out with this.

You have two issues here:
The first is that you are using the Arduino core library and failed to
initialize it. This is done automatically if you rely on the core's
supplied main(), i.e. you stick with the setup()/loop() style of
coding. If you write your own main(), you should start by calling
init() to initialize the core.
Edit: In this particular instance, you could get away by just enabling
interrupts with sei(). But I consider it good practice to initialize the
core if you are ever going to use it.
The second issue is the abrupt termination of main:
Serial.print() and println() do not really print to the serial port.
Instead, they put the characters to be printed in the output buffer, and
let an interrupt take care of actually sending them through the UART.
Your program ends with
return 0;

This will stop it. It will stop the whole program, including
interrupt-driven tasks. So you will see whatever characters did make it
to the UART, and nothing more.
If you instead end the program with and endless loop
for (;;) ;

it should work as expected.

Hmm. I was very hopeful when I saw this. It made some sense. But unfortunately it changes nothing ..

@JeroenJK: Indeed, I forgot to tell you about initializing the core. See amended answer.

Yes, sei(); works together with the endless loop. Thanks!

Arduino main() is not so simple as you think. If you use standard Arduino loop() and setup() functions it might be working much better.
But if you're not allowed to use Arduino libraries, you can use this:
src/main.cpp
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>

void section5ex34();
int uart_putchar(char c, FILE *stream);
void uart_init (unsigned long int baud);

int main(void) {
  uart_init(9600U);

  while(1) section5ex34();
  return 0;
}

void section5ex34() {
  // Initialization
  DDRC = 0b00000100; // Port C2 as output and the rest (including Port C3) as input. (Port C2 is used for a led that indicates when en bit is being read)
  PORTC = 0b11111011;

  uint8_t b = 0b00000000;

  // here the code reads bits from PORTC3
  for (int i = 0; i < 8; i++) {
    _delay_ms(100);
    PORTC |= _BV(PORTC2); // Make Port C2 high (indicates a bit will be read)

    if ((PINC & (0b1 << 3)) != 0) {
      b |= (1 << i);
    }

    _delay_ms(100); // Wait for the user to prepare the next bit (because this is now done by hand)
    PORTC &= ~_BV(PORTC2); // Then make Port C2 low
  }
  printf("0x%02X and something loooooooooooong\n",b);
}

int uart_putchar(char c, FILE *stream) {
  if (c == '\n') uart_putchar('\r', stream);
  loop_until_bit_is_set(UCSR0A, UDRE0);
  UDR0 = c;
  return 0;
}

// function to initialize UART
void uart_init (unsigned long int baud) {
    unsigned int baudrate = F_CPU/(baud*16UL)-1;
    UBRR0H = (baudrate>>8);             // shift the register right by 8 bits
    UBRR0L = baudrate;                  // set baud rate
    UCSR0B|= (1<<TXEN0)|(1<<RXEN0);     // enable receiver and transmitter
    UCSR0C|= (1<<UCSZ00)|(1<<UCSZ01);   // 8bit data format

    //// with static FILE variable:
    // static FILE uart0fd;
    // fdev_setup_stream((&uart0fd), uart_putchar, NULL,  _FDEV_SETUP_WRITE);
    // stdout = &uart0fd;

    //// or directly by using dynamically allocated FILE struct:
    stdout = fdevopen(uart_putchar,NULL); // uses malloc/calloc, it might be inconvenient
}

Well, the thing is, this is an exercise for school. I submitted it because the right HEX-value is displayed, so good enough for now, but we are not allowed anymore to use loop and setup. So if there is another way to make it work, it would be nice.

@JeroenJK: You are not allowed to write setup() and loop() and yet you can use Serial? This makes little sense to me: if any functionality of Arduino core is OK, then setup() and loop() are the most standard way to use it. Anything else, including my answer, is just a hack.

@JeroenJK Well, if I use initVariant() build fails on multiple definitions of main. So you have to skip whole arduino.h and use old school registers and so on. Or printf, but it's not so easy...

@EdgarBonet You are totally right here. I think that in a later class they will explain USART to us. But we may use other Arduino.h functionalities throughout the entire course, which is strange, yes. I first used crosspack which couldn't include Arduino.h easily, but that wasn't sufficient ..

@JeroenJK see updated code, it doesn't even need anything from arduino

You're amazing! I will definitely try to use this! Looks good and not even very complicated.

@JeroenJK Only complication was C++. I have to use .c file for FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); because it just can't be compiled in C++.

@KIIV: fdev_setup_stream() (lowercase) is less convenient, but it should compile in C++.

@EdgarBonet You are correct and It looks even better with fdevopen.


text:
Why is LED lid when pin is set low?
I made this simple piece of code, to make my LED flash.. Which it does when the pin is set low.. But how does that makes sense?
#include "pins_arduino.h"

void setup() {
  // put your setup code here, to run once:
  pinMode(BUILTIN_LED,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(BUILTIN_LED,LOW);
}

I am using the Wemos d1 - http://www.wemos.cc/

That depends entirely on how the LED is wired up. How have you wired your LED?

I am using a wemos d1

What's a wemos d1?

I am using this one http://www.wemos.cc/Products/d1_mini.html

I see no LED on the schematic. Do you mean the one built in to the ESP-12F module?

yes i am using the builtin led

If you can find a schematic of the internals of that proprietary module then you are a better man than me. But I will take an educated guess.

http://www.wemos.cc/Products/images/d1_mini.pdf
Schmatic

I said module. Not development board. The ESP-12F module. The silver can sub-circuit.

If the LED is ON when LOW and OFF when HIGH then chances are the LED is connected between +3.3V and the IO pin with a suitable resistor.
When HIGH the IO pin is at +3.3V, so the voltage across the LED is 0V (3.3 - 3.3 = 0) and it is turned off.  When LOW the IO pin is at (nearly) 0V and the voltage across the LED (and its resistor) is 3.3V (3.3 - 0 = 3.3), so it lights up.


text:
Use transistor to press button on external device
I have a small device with a simple push button. I'd like my Arduino to be able to make the device register button pushes. It seems like the best way to do this is to use a transistor to close the circuit for the button when my Arduino sends it a pulse from one of its pins. I've mapped out what I think the circuit should look like on a breadboard. I didn't include the device in this diagram, but it's powered by a CR2032 watch battery, which seems to give 220 mAh at 3Vs.
Basically, the two sides of the button would be connected to the transistor's collector/emitter leads. Then the digital pin on my Arduino would be connected via a resistor to the base lead on the transistor. When the pin sends some current to the base lead, the transistor will make current flow through it and the device will register a button press.

I made this by adapting the circuit here, which looks like this:

Basically I got rid of the motor/load and flyback diode, and hooked the two ends of the device's button up to the collector/emitter leads of the transistor.
I'm concerned that I've screwed up this circuit somehow, and will fry either the device or the Arduino or something else when I try and run it, otherwise I'd just test it right away.
Could anyone give me feedback if I'm on the right track here? I couldn't find other answers which dealt with quite this setup, where you are pressing a button on another device, though this question seemed related.

Yes, you have screwed the circuit up slightly.
You want to lose the red wire between the collector and +5V otherwise when you turn the output pin HIGH the transistor will explode.
Also you need to make sure that the ground of the Arduino (emitter of the transistor) is connected to the - of the target circuit and that the button you are "pressing" is an active-low system with internal pullup. If it's not then you will have to come up with another way.
An opto-isolator is a better choice than a transistor when you don't know the internal circuitry of the target device:

Comments are not for extended discussion; this conversation has been moved to chat.


text:
Good voltage and resistor value for string of LEDs
I building multiple parallel strings of 4 LEDs in series.
Since the four LEDs in series have a combined forward voltage of 12.56V at 20mA, and it's powered by 2 AA batteries, I have added a voltage booster.
Now my question is, since I can both choose the output voltage of the boost converter, and the resistor added to each string of 4 LEDs, what would be a reasonable value for both?
I could set the voltage to exactly 12.56V and not use a resistor, but that would probably lead to uneven current spread between the sets of 4 LEDs, as their forward voltage can differ slightly due to manufacturing differences.
On the other hand, I don't want to set the voltage too high, and wast a lot of power.
So what would be an acceptable voltage drop over a current limiting resistor?

I think the The answer depends the on what you mean exactly by a "lot of power" (to work out the LED resistor value) and how bright (very bright in daylight, ok to be visible in dark only?) you want the LED to be.

@qwerty10: Brightness is dependent on current, which has been fixed at 20mA. The only power consideration (for this question) is power loss in the ballast resistor.

@Ignacio Vazquez-Abrams I didnt notice it said 20ma. But I do now. I guess it could be 19.5ma rounded up to 20ma.

Since the relation between voltage and power is quadratic, the obvious answer is "as little as possible".
Allowing for 3% variance in VF gives us just under 13V, so that is a reasonable starting point. Solving for R gives 22ohms, a E24 value. This will result in a 8.8mW loss, which even a 0201 resistor can handle.

Thank you for your explanation. I was already leaning towards 22 ohm as a somewhat wild guess. 0201 is still a bit too small for me, but I plan on ditching the 0805 for 0603 pretty soon. 0805 is quite big if your want to create small PCBs.

I could set the voltage to exactly 12.56V and not use a resistor, but that would probably lead to uneven current spread between the sets of 4 leds, as their forward voltage can differ slightly due to manufacturing differences.

While that is a completely true statement, by having multiple LEDs in a chain you effectively average out the forward voltages. The more LEDs you have in your chain the more "average" each chain gets.
It's still not good to rely on the forward voltage to set the current, since it also varies with temperature (as the LEDs heat up the current will rise, leading to more heat and therefore more current, until you get thermal runaway).
As Ignacio says, the less the better when it comes to the resistance, and has recommended 22Ω and 13V, which I would recommend too.
Another option is to use a low-side constant current sink on each chain. This will guarantee that the current is exactly what you want (within reason) with no thermal drift in either the LEDs or the resistor.
You can find some example circuits here: http://www.radio-electronics.com/info/circuits/transistor/active-constant-current-source.php
Or you can use constant-current sink LED driver chips, which also often gives you the advantage of being able to control each chain of LEDs individually - either on/off, or PWM.

Using a boost converter and a resistor to limit current seems rather inefficient. The resistor is used to approximate a constant current source, but it would be far more efficient to use a switch mode supply to generate a constant current.
There are dedicated LED controllers which do this, although usually used with higher power LED e.g. CREE LED.
It may be possible to modify the feedback circuit in the boost converter to regulate the current, monitored with a small series resistor.

The issue is that there are multiple parallel strings, which would mean that a) ballast resistors would be required regardless, and b) failure of a single string will cascade to the other strings.


text:
Determining if an LED on another device is on
I'd like to check if this circuit I'm making is correct -- I'm concerned I'll mess up my Arduino. Essentially, I would like to determine if an LED on another device is on or not by measuring the current etc running through it. I know that device uses a CR2032 watch battery, with 3V and 220 mAH. I'd rather not do this using a photosensor since there will usually be a lot of ambient light.
I looked at this answer, and tried to adapt its circuit, which looks like this:

The solution I came up with would look like this on a breadboard:

Not pictured is the existing connections to the two leads of the LED of the device, which send current through it.
I was hoping that with this setup I could measure the current hitting the analogue input of my Arduino when the LED is turned on by the device, and in doing so figure out when the device LED is on.
Does this circuit seem accurate, or is there something I need to change? Thank you!
Edit:
Would this simpler circuit work, given that the device only has 3Vs?

Since the device is only 3v you could connect the "power" directly to a digital pin and read HIGH when the led is on and LOW when it is off.

Would the edited connection diagram I made above reflect what you mean by this? Basically just connecting straight to the Arduino.

Depending on the led type you might need to connect to the resistor, but that's basically it.


text:
Object can't get the right value of its property
I'm doing a program for a robot and I got stuck at a weird problem:
I have classes defined for my robot's internals, for example for a StepMotor. I also defined a class for a Controller, which is going to control the speed of each StepMotor.
Here's a fragment of my code:
    #include <SPI.h>
    #include <Tone.h>
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>

    /SILNIKI KROKOWE:
    class StepMotor: public Device
    {
        public:
            int motorPin;
            int dirPin;
            int sleepPin;
            int ForwardState;
            volatile double Speed;
            volatile int ControlValue;  //the value sent to the motor
            int MaxControlValue = 4000; //maximum ControlValue
            String Name;

            void Init ( void )
            {
                //init
            }

            void SetSpeed ( int speed )
            {
              toneObject.play(speed);
            }

            void SetMode(bool IsOn)
            {
              if (IsOn)
                digitalWrite(sleepPin, HIGH);
              else
                digitalWrite(sleepPin, LOW);
            }

            void SetDirection ( Dir direction )
            {
    //code for setting direction
            }

        private:
          Tone toneObject;
    };

    StepMotor motor_right;
    StepMotor motor_left;

    class Controller
    {
      public:
        ControllerType controllerType;
        double Kp;
        double Ki;
        double Kd;
        double Tp; //czas próbkowania
        volatile double e;
        volatile double e_old;
        volatile double P_result;
        volatile double I_result;
        volatile double D_result;
        StepMotor Motor;

        int Calculate ()
        {
          int Result;
     //Serial.print(Motor.Speed); HERE's THE PROBLEM
    /********************************
    /********************************
    /*******************************
          e = MoveOrder::speed - Motor.Speed;  //Motor.Speed is always 0.00, although it's not true

             //the rest is not important
        }

        void Reset()
        {
          //reset procedure
        }

    };

    Controller controller_right;
    Controller controller_left;

    setup()
    {
       controller_right.Motor = motor_right;
       controller_left.Motor = motor_left;
    }

    ISR(TIMER5_COMPA_vect)
    {
        motor_right.ControlValue = controller_right.Calculate();
        motor_left.ControlValue = controller_left.Calculate();
        motor_right.SetSpeed(motor_right.ControlValue);
        motor_left.SetSpeed(motor_left.ControlValue);

    }

I have cut the less important parts. The rest works properly, because my robot can drive when I use SetSpeed(somevalue); The only problem is that place where I need to read current speed of my motor.
In the Controller class, there's Calculate() method. In that method I want to calculate e = MoveOrder::speed - Motor.Speed; Unfortunately it can't be calculated properly, because Motor.Speed ALWAYS is 0.00 (when I display it with Serial.print(Motor.Speed) I see 0.00 all the time). It's very strange, because when I display speed of each motor (Serial.print(right_motor.Speed) or Serial.print(left_motor.Speed)) the value is correct (when the wheels are spinning, value is not 0.00).
The speed calculations are in a different function, which I didn't present here, because it would be too long - I'm sure it works, because, as I said, I can get speed values properly.
As you can see in setup(), I set each contorller's Motor porperty to the correct object.
I also used volatile keyword for the properties that are used in the interrupt.
What is wrong with my code?
If the code I provided isn't enough, here's the full version:
https://1drv.ms/t/s!Atl-jM_xUkz1hc1f-qYYotj-pJIgUw
I'm not sure if anyone would want to dive into it, because it's not so short.

My guess: controller_right.Motor = motor_right; makes a copy of motor_right. So you don't have the same class instance.
Basically Controller controller_right; calls default constructor which includes also default constructor for the StepMotor. And later all variables are copied into it by using default assigment operator, but still, it's not the same instance.

looks like you're right. So, I think I should: change StepMotor Motor in Controller class to StepMotor* Motor, to have a pointer. Then, in setup()   should do controller_right.Motor = &motor_right; and controller_left.Motor = &motor_left; Am I right?

@Loreno Or you can add StepMotor & motor_right = controller_right.Motor; after controller_* variable declaration. I guess, you can even skip these motor_right/motor_left variables as it's already in Controller

I need to be able to access motor_right and motor_left in other places (for exmple when I measure the speed of a motor and assign it to its Speed property). Your solution uses reference, right? i don't fully understand these, so I'm not sure what's the difference here. Today I can't check if the robot works correctly after applying those fixes, tomorrow I'll be able to do it and then I'll mark your answer as a proper one.

@Loreno It's basically an alias for referenced variable.


text:
Arduino Due: multiple TCS sensors
I am trying to run 2 TCS3200’s from one Arduino Due. Next, I must increase to 4 sensors. I need to read the data from the 2 digital pins but how do I read both within the same loop rather than in series to save time. The code reading one sensor tasoOutPin1 (pin 10) works but why can’t I place the second read command int detectColor(int taosOutPin2) before the { symbol?
int detectColor(int taosOutPin1) {

float white1 = colorRead(taosOutPin1,0,1);
float red1 = colorRead(taosOutPin1,1,1);
float blue1 = colorRead(taosOutPin1,2,1);
float green1 = colorRead(taosOutPin1,3,1);
}

Thanks,
Scott

What happens when you place the second / third / fourth read in?  Why doesn't it work?

Downvoted because you didn't provide enough information for us to help you and you didn't respond to the request for more information.

Seems you have to run these serially, but not sure why it's an issue, a due is quick.
seems more programming related... 'detectColor' is a function, and this is run inside the loop i assume.
int taosOutPin1 = 10; //color detector 1
int taosOutPin2 = 2; //Pins are examples, change to actual pin...
int taosOutPin3 = 3;
int taosOutPin4 = 4; //color detector 4

typedef struct {
   float white;
   float red;
   float blue;
   float green;

} color;

void setup() {
  // put your setup code here, to run once:

}

void loop() {

color detectedColorForSensor1 = detectColor(taosOutPin1);
color detectedColorForSensor2 = detectColor(taosOutPin2);
color detectedColorForSensor3 = detectColor(taosOutPin3);
color detectedColorForSensor4 = detectColor(taosOutPin4);

Serial.print(detectedColorForSensor1.red);
Serial.print(detectedColorForSensor1.green);
Serial.print(detectedColorForSensor1.blue);
Serial.print(detectedColorForSensor1.white);

//etc for sensor 2,3,4............

}

color detectColor(int taosOutPin1) {

color detectedColor;

detectedColor.white = colorRead(taosOutPin1,0,1);
detectedColor.red = colorRead(taosOutPin1,1,1);
detectedColor.blue = colorRead(taosOutPin1,2,1);
detectedColor.green = colorRead(taosOutPin1,3,1);

return detectedColor;

}


text:
Pinball - "All Lanes Lit" Bonus score is not behaving as expected
I'm trying to build a (very basic) pinball machine with an Arduino Uno. This part of the code will detect when a ball passes 3 lanes. When a lane is passed, it will activate the lane(laneState), reward a score(+10) and light up an LED.
The Expected Result:

When all 3 lanes are LIT, assign a score of the lane passage(+10), assign a bonus score(+100) and reset all laneStates to 0 and turn all leds to LOW.
110 points are being added in total

Actual Result:

the last lane passed lights back up as active (while I set all of them to inactive)
120 points are being added in total (instead of 110?)

Any hints on why I see this behaviour are very welcome!

The sketch and board can be found here: https://circuits.io/circuits/2739062-poc-lane-passage-001/
Turn on 'Code Editor' and enable the Serial Monitor to see the scores.

More info:
I looked into using interrupts, but that is not an option here (the Uno only has 2 pins for interrupts, I need 3)
Thanks!
EDIT: added the code here too:
// Scores
int totalScore = 0;
const int lanePassageScore = 10; // 10 points for passing a lane
const int allLaneActiveBonus = 100; // 100 points for activating ALL lanes

// Digital pins to detect the state of the buttons
const int laneButtonPin[] = {2,3,4};
const int laneStateLedPin[] = {10,11,12};

// all three lanes are 'inactive' at the start of the game
int laneButtonState[] = {0,0,0};
int lastLaneButtonState[] = {0,0,0};
int laneState[] = {0,0,0};

void setup() {
  Serial.begin(9600); // for debugging
}

void loop() {
  // detect if lanes 1 to 3 were activated
  detectLaneButtonPassage(0); // Lane 1
  checkAllLanesLit();
  detectLaneButtonPassage(1); // Lane 2
  checkAllLanesLit();
  detectLaneButtonPassage(2); // Lane 3
  checkAllLanesLit();

  Serial.println(totalScore); // for debugging

  delay(5);
}

void detectLaneButtonPassage(int laneId){
  // Check state of the button
  laneButtonState[laneId] = digitalRead(laneButtonPin[laneId]);
  if(laneButtonState[laneId] != lastLaneButtonState[laneId]){
    if(laneButtonState[laneId] == HIGH){
      // The lane button change to an ON position, toggle the lane state
      if(laneState[laneId] == 0){
        // lane was not yet active, it becomes active now
        laneState[laneId] = 1;
        digitalWrite(laneStateLedPin[laneId], HIGH);
        rewardScore(lanePassageScore);
      }else{
        // lane was already active, it becomes inactive now
        laneState[laneId] = 0;
        digitalWrite(laneStateLedPin[laneId], LOW);
        rewardScore(lanePassageScore/2);
      }
    }
  }
  lastLaneButtonState[laneId] = laneButtonState[laneId];
}

void rewardScore(int score){
  totalScore += score;
}

void checkAllLanesLit(){
  // Check if ALL lanes are activated
  if(laneState[0]==1 && laneState[1]==1 && laneState[2]==1){
    // reset all buttons and states
    for(int laneId=0; laneId<=2; laneId++){
      laneButtonState[laneId] = 0;
      lastLaneButtonState[laneId] = 0;
      laneState[laneId] = 0;
      digitalWrite(laneStateLedPin[laneId], LOW); //Turn off led
    }
    rewardScore(allLaneActiveBonus);
  }
}

There are 2 lines of code that need to be removed from the checkAllLanesLit() function in order for your code to work as desired:
  laneButtonState[laneId] = 0;
  lastLaneButtonState[laneId] = 0;

Explanation:
What is happening is that the detectLaneButtonPassage() is firing as normal. Then checkAllLanesLit() runs and clears the lastLaneButtonState flag.
The program loops around again and the lane button is still pressed. However, the detectLaneButtonPassage() fires again because lastLaneButtonState has been reset and it appears to the program as a rising edge. Hence the extra 10 points.

On a side note, the following 2 lines could be reduced down to a single line:
if(laneButtonState[laneId] != lastLaneButtonState[laneId]){
    if(laneButtonState[laneId] == HIGH){

The above lines of code are detecting a rising edge. They can be expressed as:
if(laneButtonState[laneId] && !lastLaneButtonState[laneId]){

For the if statement to fire laneButtonState must be high and lastLaneButtonState must be low.

I'll try this asap. Thanks for your time already.

Works perfect!  Now it makes sense to not have those lines there. I'm also not that experienced/efficient yet with condensing 2 lines of code in one. But i'll definitely keept this in mind for later! Thx again!

Looks like a timing issue.
Which ever order you hit the buttons in the last one always stays lit (and you get an extra 10 points added).
I set a breakpoint at:
rewardScore(allLaneActiveBonus);

...and just waited a sec and then continued and your code worked as expected.
So I think that you are setting all lines to LOW in checkAllLanesLit() and then only have a short delay (5mS) before looping round and checking again (at which point the button is still HIGH as you haven't taken your finger off it quickly enough) - resulting in the additional 10 points and that lane being lit again.

authors: Усердный бобёр

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


text:
Using an LM339 IC as a motor driver
I have an LM339 IC from Radioshack that I am hoping to use as a motor driver.
I read many resources on how the L239D can be used as one.  I don't have enough circuit experience to truly know the difference between the two and googling shows many wiki pages I couldn't fully understand.
Can the LM339 be used as a motor driver?
I did a quick comparison of the two circuits here LM339  and L239D
But I am still unsure.  I don't want to fry my board so I am asking first.

I looks as if it's doable.  http://forums.parallax.com/discussion/112585/lm339-h-bridge

Yes I think its doable too . This is an interesting question it reminds me of all the less obvious applications of the 55 timer. I guess the answer to your question is basically yes you could use it to drive a small motor (uses less than or same as 20ma and less or same as than 1.5v.

For example, It would be a variation of a battery comparator circuit with the LED replaced by a small motor with flyback diode, and it would be set to trigger at arduino 5v. Note that directly connecting such a motor to the arduino output pint would damage the Arduino (e.g. it would not output the high current properly once it was damaged with such a small motor). I think it would need more than one LM339 (though maybe its possible with one LM339) arranged in a clever way to protect the arduino and drive the motor.You may also need to add a few cheap parts too for the circuit.

@qwerty10 thanks for your answer!  It's a lot of trouble.  I went ahead and ordered the L239D.  I am writing up the code while I wait on delivery.

The LM339 is a comparator, not a motor driver. The L239D is a dual H-bridge motor driver.
They are completely different things. One is used for comparing two voltages (up to 4 times, it's a "quad"), the other is used for driving motors.
The LM339 can output an absolute maximum of 20mA. That's half what the Arduino itself can output on an IO pin!
You could use the LM339 as part of the control circuitry to control a H-bridge, but it cannot itself drive a motor in any way, shape, or form.

Not to mention the 16mA drive capability is only for the LOW level. The HIGH level current is rated in nA (which is more likely leakage current). Outputs for the Comparator OP AMPs are typically open-collector and they also needs external pull-up.


text:
Interfacing arduino with LabVIEW
I have already downloaded the arduino package for LabVIEW, MakerHub LINX, NI-Visa, and I've uploaded LIFA_Base to arduino, and it still does not work :(.
My questions are:
1) Do I need to upload the LIFA_Base to arduino every time I want to interface arduino with LabVIEW, or is once enough? (the order I'm following is: upload LIFA_Base -> upload my arduino code -> run the LabVIEW code)
2) I know my arduino UNO is receiving info by the LabVIEW software because the RX led goes on every time I press the ON/OFF buttons, what could be the problem?
The ideia of this humble project is to turn on/off LED through the LabVIEW. The arduino code follows the LebVIEW code.

String c, string;
int led = 2;

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

void loop() {
   if (Serial.available() > 0) string = "";

   while(Serial.available() > 0)
   {
     c = (byte)Serial.read();
       if (c == ":")
       {
         break;
       }else
       {
         string += c;
       }
     delay(1);
   }

   if (string == "LL")
   {
     digitalWrite(led, HIGH);
   }
   if (string == "DL")
   {
     digitalWrite(led, LOW);
   }
}

Long time LabVIEW and Arduino user, but never used LIFA.  I did a quick look at the getting started for LIFA. If I'm not mistaken, do you even need to upload your own Arduino code? Doesn't the LIFA_Base.pde take care of the interpretation of these serial commands for you, or am I totally missing something?

I have just started to combine arduino with LabVIEW, so I have no  experience to tell if you are actually missing something. How did you use to work with arduino and LabVIEW? Because I think I am mixing up different ways to do the same thing and that's why it's not working. Did you use the arduino elements from LabVIEW or just the VISA ones? Thanks!!

I've personally always just used VISA elements, and then wrote Arduino code similar to like what you have above.  But the LIFA elements look like they would be easier to get started with! And for that I'm pretty sure you just want to upload LIFA_Base.pde to the arduino.

From the LabVIEW side of things, I would just go with an event structure and use a single boolean to control the LED - let it go idle when the button state has not changed. No need to poll!

“upload LIFA_Base -> upload my arduino code”. You can only have one program in the Arduino at a time. When you upload your Arduino code, you are overwriting the previously uploaded LIFA_Base.


text:
Sending uint16_t over I2C
How do you transmit and read a uint16_t over I2C?
I'm trying to read two uint16_t values from a slave device, and I'm seeing nonsensical readings.
This is the code on my slave Arduino Uno:
#include <Wire.h>

void send_wire_int(uint16_t num){

    // Send low byte
    Wire.write((uint8_t)num);

    // Send high byte
    num >>= 8;
    Wire.write((uint8_t)num);
}

// This is called from the I2C host.
void I2C_Send()
{

    //  send_wire_int(acount_abs);// Send encoder A count.
    //  send_wire_int(bcount_abs);// Send encoder B count.

    send_wire_int(0);
    send_wire_int(0);

}

void setup(){

    Wire.begin(30);                                                        // initialize I²C library and set slave address
    Wire.onRequest(I2C_Send);                                                   // define I²C slave transmit ISR

    Wire.flush();
    Wire.setTimeout(1000L);

}

void loop(){
    //stuff
}

All it does is wait for the master to request data. Originally, it was sending the values of two registers back, but these values were also garbled or non-changing, so I changed it to just send back 0s but I still get the identical garbled values.
This is the code on my master Arduino Uno:
#include <Wire.h>

uint16_t receive_wire_int(){

    while(Wire.available() < 1){}

    // Read low byte into rxnum
    uint16_t rxnum = Wire.read();

    while(Wire.available() < 1){}

    // Read high byte into rxnum
    rxnum += Wire.read() << 8;

    return rxnum;
}

void setup() {
    Wire.begin();        // join i2c bus (address optional for master)
    Wire.setTimeout(1000L);
    Serial.begin(9600);  // start serial for output
}

void loop() {
    Serial.println("Requesting data..."); Serial.flush();

    Wire.requestFrom(30, 4);

    uint16_t acount = receive_wire_int();
    uint16_t bcount = receive_wire_int();

    Serial.println(String("acount:")+String(acount)+String(" bcount:")+String(bcount));

    delay(500);
}

As you can see, it simply requests the two uint16_t values in 4 bytes, and then prints them to the Serial (my laptop's terminal).
The output I'm seeing is:
acount:65280 bcount:65535

when I would expect:
acount:0 bcount:0

What I am I doing wrong?

What is the I2C clock rate on the master? You set it on the slave but not the master device.

Seems like all the calls to Wire.read(), save for the first, return -1, which becomes 0xffff when cast to uint16_t. Could you check for this condition?

Do the two Arduinos share a common ground?

@Andrew, The clock speeds are both the default/standard 100k.

@EdgarBonet, You're correct that read() returns -1 if nothing is received, but why would that only be happening for 2 of the 4 bytes?

@Matt, Yes, the I2C connection includes the SCL/SDA pins as well as Vcc/Gnd.

@Cerin - Had to check I assume you have pull up resistors too.  I think the read function will return -1 if there is no data.  Which is strange because the available function says there is 4 bytes of data.  What happens if the 1ms timeout expires?  Can you make the timeout stupidly large?  You are getting -1 for 3 bytes not 2.  The second byte (acount MSB is also -1).  Should there be a Wire.available() call in your read function to wait for the second byte to become available?

@Matt, Yeah, it looks like maybe only one byte is making it over, and the other read() calls are returning -1. I tried changing the timeout to 1000ms, but that had no effect. I also changed the reads to wait for each byte individually, but that also had no effect.

@Cerin - Have you looked at the write function in the same way?  would adding a delay statement between the writes help?  Does Write.write() return a value, is it possible that you are only writing one byte of data?

So I've just tested your code and apparently you have to send all data at once. After some research: it sends characters into the function twi_transmit and this function just fills the buffer and actual data are sent asynchronously. So, if you are fast enough, you will overwrite the buffer with another bytes and it's still like you have only 1 character to send.
For example this works (AVRs are little endian):
#include <Wire.h>

// This is called from the I2C host.
void I2C_Send()
{
    uint16_t   uints[2] = {0xDEAD,0xBEEF};

    Wire.write((uint8_t*) uints, 4);
}

void setup(){
    Wire.begin(30);  // initialize I²C library and set slave address
    Wire.onRequest(I2C_Send); // define I²C slave transmit ISR

    Wire.flush();
    Wire.setTimeout(1000L);
}

void loop(){
    //stuff
}

And receiver with HEX prints:
#include <Wire.h>

uint16_t receive_wire_int(){

    while(Wire.available() < 1){}

    // Read low byte into rxnum
    uint16_t rxnum = Wire.read();

    while(Wire.available() < 1){}

    // Read high byte into rxnum
    rxnum += Wire.read() << 8;

    return rxnum;
}

void setup() {
    Wire.begin();        // join i2c bus (address optional for master)
    Wire.setTimeout(1000L);
    Serial.begin(9600);  // start serial for output
}

void loop() {
    Serial.println("Requesting data..."); Serial.flush();

    Wire.requestFrom(30, 4);

    uint16_t acount = receive_wire_int();
    uint16_t bcount = receive_wire_int();

    Serial.print("acount: 0x");
    Serial.print(acount,HEX);
    Serial.print("  bcount: 0x");
    Serial.println(bcount,HEX);

    delay(500);
}

The problem is that I'm using the wrong type of write() in my slave. As this blog explains, there are two overloaded write() methods in the Wire library. One that accepts a single byte, and another that accepts a byte array. I was sending each byte separately, which doesn't guarantee they'll be received together.
It works if I rewrite my slave's to:
void I2C_Send()
{
  byte myArray[4];

  myArray[0] = 0;
  myArray[1] = 0;
  myArray[2] = 0;
  myArray[3] = 0;

  Wire.write(myArray, 4);

}


text:
ESP8266 GET REPLY ERROR 501
I am trying to build a home automation system and i am unable to get data from a website using the arduino sketch, however i am able to get data from the website when i enter the AT commands into the serial monitor.Below is my sketch:
#include <SoftwareSerial.h>

SoftwareSerial esp8266(4,5);

void setup(){
  Serial.begin(9600);
  esp8266.begin(115200);
  esp8266.println("AT+CIPMUX=1\r\n");
  delay(2000);
  esp8266.println("AT+CIPSTART=0,\"TCP\",\"www.homeautomationserver.com\",80 \r\n");
  delay(2000);
  esp8266.println("AT+CIPSEND=0,75");
  esp8266.println("GET /f/pw9e1acqx7yb0gl.txt HTTP/1.1\r\n");
  esp8266.println("Host:www.homeautomationserver.com\r\n\r\n");
}

void loop(){

  if (esp8266.available()){
    Serial.write(esp8266.read());
  }
  if (Serial.available()){
    esp8266.write(Serial.read());
  }
}

I get a 501 not Implemented error from the server.
Please Help.
Thanks

http://www.computerhope.com/issues/ch001020.htm

You should really include Connection: close in your headers as well, so the server doesn't try and keep the connection open longer than needed.

Content-length: ??? might help too.  (??? should be the message size)

@Matt Content-length would be 0 - there is no body there to have a length. It's not strictly needed, especially if the sending pipe is manually closed by the client.

Maybe you should replace esp8266.println() with esp8266.print(), because you already append "\r\n" in your strings.

Can you use you favourite web browser and retrieve the page http://www.homeautomationserver.com/f/pw9e1acqx7yb0gl.txt ?
If you can then the problem is with your client, if not its with the address you are requesting or the server.
The fact you are getting a 501 error indicates that GET is not supported for this resource.  So check that you are using the correct method?
Get yourself a REST console (there is an add-on for chrome and plenty of others) try typing the command in manually to see if you can identify the fault.
Look at Wikipedia for a list of error codes, it might give you a clue as to what is wrong.
And don't you need a AT+CIPSEND after you have printed the http packet?

And don't you need a AT+CIPSEND after you have printed the http packet? - no that comes beforehand. The numbers indicate how many bytes you are about to send so it knows how many to expect.

@Majenko - OK, thanks for the correction, I just saw an example that had the send after the header, maybe it was sending an empty body(?).

If the send is after any form of data (including the header) the data will be interpreted as ESP8266 AT commands and will fail. The example you found must be horribly broken.

Thanks for your reply , I have tried using your code and this time i am not receiving any reply from the server. i have also noticed that using my code i sometimes receive a 400 error -bad request as well followed by the 501 error after a few tries .i am so confused with the error codes generated by the server.

Sorry Matt i was trying to reply to Majenko and thank you for your reply as well, I know the issue is with my sketch but cannot figure out what exactly is the problem.

Your problem lies in these lines:
esp8266.println("AT+CIPSEND=0,75");
esp8266.println("GET /f/pw9e1acqx7yb0gl.txt HTTP/1.1\r\n");
esp8266.println("Host:www.homeautomationserver.com\r\n\r\n");

You are mistakenly using println() instead of print() when sending the data. That imposes its own <CR><LF> sequence on the end of the lines, yet you are adding the <CR><LF> manually.  You are also incorrectly specifying 75 characters to send, so the result of all that is:
GET /f/pw9e1acqx7yb0gl.txt HTTP/1.1\r\n              37
\r\n                                                  2
Host:www.homeautomationserver.com\r\n                35
\r                                                    1
                                                   ----
                                                     75

I.e., your request is garbled. You need to change the println() to print() for the data printing and make sure the character count is correct:
esp8266.println("AT+CIPSEND=0,74");
esp8266.print("GET /f/pw9e1acqx7yb0gl.txt HTTP/1.1\r\n");
esp8266.print("Host:www.homeautomationserver.com\r\n\r\n");

GET /f/pw9e1acqx7yb0gl.txt HTTP/1.1\r\n              37
Host:www.homeautomationserver.com\r\n                35
\r\n                                                  2
                                                   ----
                                                     74

You should also include more detail and commands in your headers. Things like the length of the body (0 bytes) and the fact that the connection should be closed, and there really should be a space after the colon on the Host: header:
esp8266.println("AT+CIPSEND=0,113");
esp8266.print("GET /f/pw9e1acqx7yb0gl.txt HTTP/1.1\r\n");
esp8266.print("Connection: close\r\n");
esp8266.print("Content-Length: 0\r\n");
esp8266.print("Host: www.homeautomationserver.com\r\n\r\n");

GET /f/pw9e1acqx7yb0gl.txt HTTP/1.1\r\n              37
Connection: close\r\n                                19
Content-Length: 0\r\n                                19
Host: www.homeautomationserver.com\r\n               36
\r\n                                                  2
                                                  -----
                                                    113

Thanks for your reply , I have tried using your code and this time i am not receiving any reply from the server. i have also noticed that using my code i sometimes receive a 400 error -bad request as well followed by the 501 error after a few tries .i am so confused with the error codes generated by the server.


text:
SD card shield not working on 3.3v
My SD shield works nicely on 5v supply, but does not detect SD card on 3.3v. Could someone explain the possible reason behind this? Could you also provide a solution for this?
I've worked with it on Arduino Uno. Now I want to use SD card directly with ESP-12E to read its contents using SPI by doing something like this. Since ESP8266 operates olny on 3.3v, I need SD card to work on this voltage.
I've used two separate SD card shields without any luck! Photos of the two shields and micro-SD card are attached.

Are we supposed to guess what your circuit is doing? The only info you provided was a few pictures of the readers. What are the wires connected to?
Are you saying you connected 3.3V to the "3V3" pin and left the "5V" pin open?

How do you know it's the card reader and not your code that is at fault?

The circuitry is actually a pretty straight-forward SPI (MOSI-MOSI, MISO-MISO, SCK-SCK, CS-chipSelectPIN, GND-GND, VCC-VCC).
Yes, I connected 3.3V to the 3V3 pin and left the 5V pin open.

It's probably the fault of shield because it works when I supply 5V to it.

@AshishRanjan "VCC-VCC"? That's not helpful either. What is the other VCC? Realize that it's important to document what is going on. You're asking for help, it's best to give us as much info as possible.

@AshishRanjan That being said, 3.3V connected to the "3V3" pin should be sufficient. Try measuring the current being used on that pin, maybe that could show something interesting.

Sorry if I seem too vague. VCC could be anything from 3.3V to 5V. What I meant was, when I connect 5V to VCC, I am able to read the contents of SD card, but if I supply 3.3V to VCC, I'm not able to read or even detect the presence of the SD card.

@AshishRanjan I understand your issue, I do not understand what you connected to VCC! Where is the wire going!?

The VCC wire is going to the 5V of Arduino Uno (or the 3.3V). The GND wire is going to GND of Uno. Similarly
MOSI - pin 11
MISO - pin 12
CLK - pin 13
CS - pin 4

I believe the 3.3V rail also uses current from the 5V rail on arduous. Perhaps there is simply not enough current on the 3.3V rail.

I'll measure the current in 3.3V as well as the 5V line tomorrow, and let you know the results. Perhaps that would help us!

I could not find any info on the full size SD card adaptor, but the microSD adaptor has a 3.3V (LM1117 or equivalent) regulator on it. It, therefore, needs a minimum of 4.5V to operate.
To run the adaptor from 3.3V, you would have to remove the regulator and solder in a piece of wire in its place.

Perhaps you are right, I'll try to run it by soldering a 3.3V wire to the output of AMS1117 tomorrow.

No need to remove the ams1117. Just adding a jumper wire between in an out will suffice.


text:
options for wireless data broadcasting to hundreds of nodes
I would like to build approx 100 arduino devices that can talk to each other, I have a set of constraints that I'm looking to get some insight on :

all devices would operate within a 300 meter proximity of each other
the devices each need to broadcast some data (their speed and
orientation from a gyro) to the rest of the devices in the group for
storage
They need to update each other roughly every 500ms/1s
Some of the devices need to be added and removed from the pool regularly
The devices need to start broadcasting their data to the rest of the
devices in the pool immediately when added (<1s delay)
The spectrum needs to be public & unlicensed

Which method of communication would you recommend? For the range, it seems like a 433hz RF transceiver and receiver would be appropriate or wifi could work but I have concerns about overloading the channels. Bluetooth seems like it has too long a handshake period and the range is too low.
Are there any other options I'm missing? What would be the best way to implement this?
Many thanks for you answers
Update : Data estimation
So the data payload I estimate consists of :
Speed (km/ph) : ok so this will be max 3 decimal numbers, so one short int should be enough here (2 bytes)
bearing : so this will be a standard bearing, let's assume between 0-360 so another short int should be fine (2 bytes)
Velocity : ok, so also a short (2 bytes)
Long : well this needs to be a 32 bit float so it's going to take 4 bytes
Lat : same as above 4 bytes
It's possible with some hackery I could combine speed, volcity and bearing into one short to only take 2 bytes. But let's assume I'm probably going to need 14 bytes, in best case 9.

nRF24L01+ with power amplifiers? Cheap on eBay...

In fact, if they are always close enough to a neighbour you could scrap the amplifiers and go for the non-amplified version and run a self-healing mesh.

Looked at Zigbee?

RFM69 or https://talk2.wisen.com.au/product-talk2-whisper-node-avr/?
Just need to do some calculation to see how load the whole network will be. Need to consider messages clashing with each other... keeping the communication as short-as-possible might be the answer.

You will need to synch the time between devices so that they know when its time to talk.  The recipient can not send a reply.

Please add an estimation of the amount of data (my guess is four integers, 8 bytes, plus possible time stamp, 4 bytes, sequence number, 1 byte, etc). Also do the basic bandwidth requirements. A simple approach is to have a beacon that marks the start of the broadcast and each node transmits according to a time slot (based on their network id). You also need to deal with dropped data.

@Mikael Patel
thanks, I have included a rough estimate in terms of data size of the payload.

@Talk2 - the whisper solution looks quite good, what kind of calculations would I need to do about the whole network to avoid clashing are there some examples online?

@jqpat7 - Thanks I looked at zigbee but the range is limited to 50m, which is too small

The nRF24L01+ solution would give the coverage and it is easy to use to implement a broadcast protocol with high bit-rate (e.g. 1-2 Mbps). The Cosa NRF24L01P device driver allows for some of the functionality required. https://github.com/mikaelpatel/Cosa/blob/master/libraries/NRF24L01P/NRF24L01P.h

I think you also need to add estimates for the amount of SRAM and the data accuracy required. Even with aggressive message filtering the amount of data required for even a small number of neighboring nodes might be much higher than available on the smaller AVR based Arduino boards.

Re Message Payload : What about an extra byte for an identifier for the transmitter, this will be necessary when the nodes are two close to each other to be differentiated by LatLong.  You only have around 5ms to collate the data broadcast it receive and store it, so you may want to look at optimised solutions rather than just high bandwidth solutions.

In terms of Radio, the RFM69 is a good option for range, speed and reliability at low cost. A board like this one https://talk2.wisen.com.au/product-talk2-whisper-node-avr/ would have all ready to go, just add your sensors.
The link can run on 433MHz, 868MHz or 915MHz band, which cover 99% of unlicensed/open frequencies worldwide.

For the protocol/software you need to reduce the message as much as possible. As you mentioned, you could have 9 bytes for the payload if you "share" some bytes, which is the correct approach in this tight network. Add some 2 extra bytes for "operation/command", "sender" and "receiver". Additional to that, you need to consider the bytes added by the radio itself, like Preamble, Sync-word, Network ID, Length, CRC, etc.

The biggest challenge in my opinion would be to not have the RF network flooded with messages, causing multiple radios to transmit at the same time and messages being lost.
Let's suppose you have a total of 20 bytes for all headers+payload per message. If your network is running at 80Kbits/sec (or 10KBytes/s), that would allow a maximum of 500 message/second (2ms per message) in a perfect scenario, without considering any kind of delay between messages.
Bring down to the real-world a 1/3 link utilization is a bit more realistic, giving you a bit over 150 messages of 20 bytes per second. In other words, if the network had an evenly message distribution a node would transmit a 2ms message followed by 6ms of silence.
Now, you can't count that 100 nodes would have perfect synchronization to send a 2ms message and stay quiet for exactly 998ms before sending a message again. There are so many variables which require you to have some sort of control.
One way of doing that is by using a pooling mechanism, where you have a "tick" or "clock" node, which is the only one allowed to talk without being asked. This node will be sending "pooling" requests, a small message with 1 or 2 bytes, containing a command and the destination address, for example: 0x99 0x0A, where 0x99 is the address of the node being polled and 0x0A is the command, like "send me the instrumentation readings, you have 2ms".
Now, instead of the node 0x99 start reading the sensors, it already have it all stored in memory and ready to go, sending the broadcast message to everyone interested. The node 0x99 will also start collecting the new sensor data and preparing the message, so as soon it'll be asked it's ready to go again.
This way you can control how noise the network is and also implement other commands to capture additional information if necessary, etc.
Another implementation would be similar to the old "Token-Ring", but I believe having a master would be more beneficial in this case.
Notes:

The RFM69 can go over 200Kbp/s, but only tests would tell the maximum reliable speed. I use 80Kbp/s to make maths easier.
Design your system so it would survive if a message is lost, like UDP packages, send it and "pray". Adding Ack and re-transmission is probably worst as it would slow down the whole cycle.
The radio also offers encryption, but it might take a few uS extra
If one node will be expected to receive every single message, bear in mind that it would have only a few milliseconds available to process the message and do whatever it needs to do before another message arrive. If you need to perform lots of processing/logs/control actuators you might need to delegate this task to other MCU(s)

Cheers,

Thanks for all the input. I really like your hardware, and think it's definitely the way to go. I am still struggling with the contention issue though. I like the master/slave, but I need all the nodes to have access to all the data from the other nodes. Also, the nodes in the pool will be swapped out fairly regularly, like one every two minutes or so, so it's highly likey the master will leave the pool and then one of the other nodes would need to take over it's responsibilities.

Understand... the only thing you need to keep in mind is that you're going to have very little time after receiving a message to do something. About a master leaving, can you control that or it would simply shut-down? If you can control, the master can send a "command" back to the last sending node to take over.


text:
How can I tell how large my program is?
Scenario
When I upload my project via the Arduino ide I see this at the bottom:
Writing | ################################################## | 100% 4.14s

avrdude: 25698 bytes of flash written
avrdude: verifying flash memory against /var/folders/r4/s_j4c02s3wvcx6wy41__rnwh0000gp/T/build5447a2e9a95ee46ba2ad71abe5de02d6.tmp/SwatBotSpine.ino.hex:
avrdude: load data flash data from input file /var/folders/r4/s_j4c02s3wvcx6wy41__rnwh0000gp/T/build5447a2e9a95ee46ba2ad71abe5de02d6.tmp/SwatBotSpine.ino.hex:
avrdude: input file /var/folders/r4/s_j4c02s3wvcx6wy41__rnwh0000gp/T/build5447a2e9a95ee46ba2ad71abe5de02d6.tmp/SwatBotSpine.ino.hex contains 25698 bytes

Question
I'm uploading to an Arduino Uno, does this mean I have 32256 - 25698 bytes left?

Only if you're using a 512byte bootloader.

@IgnacioVazquez-Abrams Are there unos with a bootloader other than 512b? I suppose people could be using custom bootloaders..

Older Arduinos used larger bootloaders, then they switched to the smaller “optiboot”. I do not know when they did the switch, but it may well be after the first Unos started shipping.

Short answer: Yes.
At the end of a successful compilation (not upload), at least in ArduinoIDE 1.6.9, the final 2 messages look like:

Sketch uses 23,442 bytes (72%) of program storage space. Maximum is
  32,256 bytes. Global variables use 1,093 bytes (53%) of dynamic
  memory, leaving 955 bytes for local variables. Maximum is 2,048 bytes.

In this case, 8814 bytes of flash remain unused, and 955 bytes remain for the use of the stack and the heap, combined.

I see it now. I was looking in the avrdude messages but the sketch info is right before that.


text:
Object Array using Inheritance
I would like to create an array of a generic type so I can use multiple sensors and make my code as extensible as possible.
/*
  Planning for good design. Agent library
  should be able to use more than one sensor.

  The agent's constructor will accept a vector
  of sensors.
*/
class Sensor
{
 public:
  Sensor(){};
};

My implementation class
#include "Arduino.h"

class UltraSonicSensor: public Sensor {
 public:
  /*
    Constructors
   */
  UltraSonicSensor(){};
  UltraSonicSensor(int pin){
    pin_ = pin;
  };
  int Sense(){ return 20;};
  /*
    Measure Distance
   */
  float DistanceMeasure(void);
 private:
  /*
    Class only suppports Metric
   */
  float microseconds_to_centimeters(void);
  int pin_;
  long duration_;
};

#endif // SROBOT_SENSORS_ULTRASONIC_H_

I have tried many, many variations of this code but always the same error
Sensor *sensors[2];

UltraSonicSensor uSensor;
sensors[0] = &uSensor;

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

void loop(){
  Serial.println("starting...");
  delay(1000);
  Serial.println("ok");
//  delay(2000);
//  for (int i = 0; i < sensors.size(); i++) {
////    sensors[i].Sense();
//  }
}

The error is always a variation of
main:10: error: 'sensors' does not name a type
 sensors[0] = &uSensor;
 ^
exit status 1
'sensors' does not name a type

I also used the code for a small replacement vector class but also the same error

You have to do it inside of function:
Sensor *sensors[2];

UltraSonicSensor uSensor;

void setup(){
  Serial.begin(9600);
  sensors[0] = &uSensor;
}

Or directly:
UltraSonicSensor uSensor;

Sensor *sensors[] = {&uSensor};

Don't forget to make method Sense() virtual in the base class and in the inherited classes. Otherwise you'll have to also find out the type of the object and typecast it to correct class pointer before it's use.
class Sensor
{
  public:
    virtual int Sense() = 0; // pure virtual base class
};

// and inherited class:

class UltraSonicSensor: public Sensor {
  public:
    // ...

    // Prototype must be exactly the same, by using override
    // is ensured it actually overrides something from the parent class.
    virtual int Sense() override {
        // ...
    }
    // ...
}

Also the last versions of Arduino IDE supports C++11 standard so you can use range based for loop:
for (Sensor * sensor : sensors) {
    int val = sensor->Sense();
    // ...
}

excellent! Thank you very much the clarification.  Tried it just now and it works

Based on the answer from @KIIV and the Vector class, the below code compiles successfully
#include "Vector.h"
#include "Sensor.h"
#include "UltraSonicSensor.h"
#include "LaserSensor.h"

Vector<Sensor*> sensors;
UltraSonicSensor uSensor;
LaserSensor lSensor;

void setup(){
  sensors.push_back(&uSensor);
  sensors.push_back(&lSensor);
}

void loop(){
  Serial.println("starting...");
  delay(1000);
  for (int i = 0; i < sensors.size(); i++) {
    int val = sensors[i]->Sense();
    // ...
  }
}