esapode688
Well-known member
Following this tutorial: http://projectsfromtech.blogspot.co.uk/2014/01/i2c-hc-sr04-sonar-module-attiny85-i2c.html
; i created a series of boards to read the distance from HcSr04 sensors.
PRecisely: 12 sensors.
I bootloaded each attiny 85 @ 16mhz and Daisychained 12 of them On the same I2c line; all powered by a 5 volt 10 amp PSU.
Each tiny board has his own 4.7k pullups and a 10k resistor between reset and 5 volt.
On each one runs this code:
Note that every Tiny has his own address and join the I2c Bus with a delay of 10 ms respect the previous.
I read all of them using this other code:
The problem is that all the line randomly hangs after a while and data stop flowing until i reset the arduino.
I tried it both on arduino and teensy 3 and i get the same problem.
Anyone got an idea on what could be?
; i created a series of boards to read the distance from HcSr04 sensors.
PRecisely: 12 sensors.
I bootloaded each attiny 85 @ 16mhz and Daisychained 12 of them On the same I2c line; all powered by a 5 volt 10 amp PSU.
Each tiny board has his own 4.7k pullups and a 10k resistor between reset and 5 volt.
On each one runs this code:
Code:
/*
This is the firmware for every I2c Sensor
NOTE: Every board should have his own unique I2c address
Define it differently for every board
This program sends just the distance value over I2c
Based on the original New Ping implementation
*/
#include <TinyWireS.h> // Requires fork by Rambo with onRequest support
#include <TinyNewPing.h> // NewPing library modified for ATtiny
const byte SensorOnePin = 3; // Sensor 1 is connected to PB3
const int I2CSlaveAddress = 12; // I2C Address.
byte Distance; // Where the Distance is stored (8 bit unsigned)
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing SensorOne (SensorOnePin, SensorOnePin, MAX_DISTANCE); // Define the Sensor
void setup()
{
delay(290); //We join the Bus with a delay based on actual channel number to avoid crossfading
TinyWireS.begin(I2CSlaveAddress); // Begin I2C Communication
TinyWireS.onRequest(transmit); // When requested, call function transmit()
}
void loop()
{
Distance = SensorOne.ping_cm(); // Get distance in cm. Could be changed to
//Distance = SensorOne.ping_median(5)/US_ROUNDTRIP_CM; // Take the median of 5 readings
delay(30); // Delay to avoid interference from last ping
} //end loop()
void transmit()
{
TinyWireS.send(Distance); // Send last recorded distance for current sensor
}
Note that every Tiny has his own address and join the I2c Bus with a delay of 10 ms respect the previous.
I read all of them using this other code:
Code:
#include <Wire.h>
byte Distance[11]; // Where the Distance is stored (8 bit unsigned)
int i,p,x;
void setup()
{
Wire.begin();
Serial.begin(115200);
Serial.println("Setup");
pinMode(13, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
//loop throug all the sensors and store their values in an array
p=0;
for (i=12;i<25;i++)
{
digitalWrite(13, LOW);
//if (i==19) i=20;
Wire.requestFrom(i, 1); // The TinyWire library only allows for one byte to be requested at a time
while (Wire.available() == 0) ; // Wait until there is data in the I2C buffer
Distance[p] = Wire.read(); // Read the first (and hopefully only) byte in the I2C buffer
p++;
delay(2);
}
delay(68);
for (x=0;x<3;x++)
{
Serial.print("S");
Serial.print(x);
Serial.print(" ");
Serial.print(Distance[x]);
Serial.print(" ");
// The sensor only updates every 30 ms. Asking for new data quicker than that is useless
}
Serial.println(" ");
}
The problem is that all the line randomly hangs after a while and data stop flowing until i reset the arduino.
I tried it both on arduino and teensy 3 and i get the same problem.
Anyone got an idea on what could be?