コード例 #1
0
ファイル: TempSensor.cpp プロジェクト: basaf/MQTT_Module
/**
*	\brief Creates a table with all sensors which are connected via OneWire.
*		
*		The table is created on the basis of a previous table which is stored
*		in the EEPROM. This helps to have a consistent assignment of the sensor ID
*		to the connected sensor. Otherwise this can change after a reset or if a 
*		sensor is removed.	
*/
error_t createAddressTable(void){
	uint8_t address[8];
	tempSensorTable.size=0;
	uint8_t index=0;
	tempSensorTable_t eepromTable;
	
	memset(&tempSensorTable,0,sizeof(tempSensorTable_t));
	
	int8_t deviceCount=sensors.getDeviceCount();
	for(int i=0; i<deviceCount; i++){
		if(sensors.getAddress(address, i)){
			memcpy(tempSensorTable.tableEntry[index].address,address,sizeof(address));
			tempSensorTable.tableEntry[index].tempSensorID=i;
			tempSensorTable.tableEntry[index].enabled=1;		//default: send temp sensor value
			++index;	
		}
	}
	tempSensorTable.size=index;
	
	if(!loadAddressTableFromEEPROM(&eepromTable)){
		//table found in EEPROM
		mergeTables(&eepromTable, &tempSensorTable);
	}
	
	writeAddressTableToEEPROM(&tempSensorTable);
	
	return ERR_NO_ERR;
}
コード例 #2
0
ファイル: Tester.cpp プロジェクト: hdo/arduino_panstamp
void loop(void)
{ 
	delay(2000);
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  
  
  // Loop through each device, print out temperature data
  for(int i=0;i<numberOfDevices; i++)
  {
    // Search the wire for address
    if(sensors.getAddress(tempDeviceAddress, i))
	{
		// Output the device ID
		Serial.print("Temperature for device: ");
		Serial.println(i,DEC);
		
		// It responds almost immediately. Let's print out the data
		printTemperature(tempDeviceAddress); // Use a simple function to print out the data
	} 
	//else ghost device! Check your power requirements and cabling
	
  }
}
コード例 #3
0
ファイル: TempSensor.cpp プロジェクト: basaf/MQTT_Module
/**
*	\brief Prints all connected OneWire sensors with there index
		and current temperature value. 
*/
void tempSensorsPrintInfo(void){
		uint8_t address[8];
		float temp;
		
		uint8_t deviceCount=sensors.getDeviceCount();
		Serial.print("Found devices: ");
		Serial.println(deviceCount);
		Serial.println(" ");
		
		sensors.requestTemperatures();
			
		for(int i=0; i<deviceCount; i++){
			Serial.print("Device: ");
			Serial.println(i);
			if(sensors.getAddress(address, i)){

				temp=sensors.getTempC(address);
				
				Serial.print("Temp: ");
				Serial.print(temp);
				Serial.println(" ");
				//delay(100);
				
				Serial.print("Resolution: ");
				Serial.println(sensors.getResolution(address));
				Serial.println("");
				//delay(100);
			}
		
		}
	
}
コード例 #4
0
void sensor_setup(){  
  temp_sensor.begin();//initialize one wire sensor
  temp_sensor.setResolution(insideThermometer, 9);  //configure sensor parameters 
  
   
#ifdef DEBUG_SENS
  // report on finding the devices on the bus or not
  if (!temp_sensor.getAddress(insideThermometer, 0)) softdebug.println("Unable to find address for Device 0");
  else{  
    
    // report parasite power requirements
    softdebug.print("Parasite power is: "); 
    if (temp_sensor.isParasitePowerMode()) softdebug.println("ON");
    else softdebug.println("OFF");
    
    sensors_temperature(); //print temperature for debugging
    
  }
  
  //print voltage sensor value for debugging
  softdebug.print("Vin=");
  softdebug.println(sensors_vin());
  
#endif //DEBUG_SENS
}
コード例 #5
0
ファイル: 5sparktemp.cpp プロジェクト: RobertNewkirk/particle
int queryDevices(String command) {

    if(command == "auto") {
    // sets and prints the device array
        for(int i=0; i < deviceCount; i++ ) {
            sensor.getAddress(deviceIndexArray[i], i);
            Serial.print("Device Index ");
            Serial.print(i);
            printAddress(deviceIndexArray[i]);
            Serial.print("\n");
        }
        Serial.print("----------------------------------\n");
        return 1;
    }

    if(command == "array" ) {
    // prints the device Array but does not set it
        Serial << "Display deviceIndexArray " << endl << "----------------------------------\n"  << endl;
        for ( int i=0; i < 5; i++ ) {
            Serial << "\n deviceIndexArray[" << i << "]: ";
            printAddress(deviceIndexArray[i]);

        }
        Serial <<  "\n----------------------------------\n" << endl;
    }



}
コード例 #6
0
void setup()
{
    pinMode(13, OUTPUT);

    // Set up all of the Digital IO pins.
    pinMode(pin_leftCutterCheck,INPUT);
    pinMode(pin_rightCutterCheck,INPUT);
    pinMode(pin_leftCutterControl,OUTPUT);
    pinMode(pin_rightCutterControl,OUTPUT);
    // Turn off the cutters by default
    digitalWrite(pin_leftCutterControl,LOW);
    digitalWrite(pin_rightCutterControl,LOW);

	// Initialize the rear panel LED outputs
    pinMode(pin_ledHigh,OUTPUT);
    pinMode(pin_ledMid,OUTPUT);
	pinMode(pin_ledLow,OUTPUT);
	digitalWrite(pin_ledHigh, LOW);
	digitalWrite(pin_ledMid, LOW);
	digitalWrite(pin_ledLow, LOW);
	
	temperatureTop.begin();
    temperatureBot.begin();
    
    // Make sure we have temperature sensors, if not, set to something
    // unreasonable. This would be 0 in Alabama.
    if(!temperatureTop.getAddress(topAddress,0))
    {
        msgStatus.temperature_1 = 0.0;
    } else {
        temperatureTop.setResolution(topAddress,9);
        temperatureTop.setWaitForConversion(false);
        temperatureTop.requestTemperatures();
    }
    if(!temperatureBot.getAddress(botAddress,0))
    {
        msgStatus.temperature_2 = 0.0;
    } else {
        temperatureBot.setResolution(botAddress,9);
        temperatureBot.setWaitForConversion(false);
        temperatureBot.requestTemperatures();
    }
    nh.initNode(); 
	nh.advertise(status_pub);
	nh.advertiseService(cutter_srv);
}
コード例 #7
0
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // locate devices on the bus
  Serial.print("Locating devices...");
  sensors.begin();
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  
  // assign address manually.  the addresses below will beed to be changed
  // to valid device addresses on your bus.  device address can be retrieved
  // by using either oneWire.search(deviceAddress) or individually via
  // sensors.getAddress(deviceAddress, index)
  //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };

  // Method 1:
  // search for devices on the bus and assign based on an index.  ideally,
  // you would do this to initially discover addresses on the bus and then 
  // use those addresses and manually assign them (see above) once you know 
  // the devices on your bus (and assuming they don't change).
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
  
  // method 2: search()
  // search() looks for the next device. Returns 1 if a new address has been
  // returned. A zero might mean that the bus is shorted, there are no devices, 
  // or you have already retrieved all of them.  It might be a good idea to 
  // check the CRC to make sure you didn't get garbage.  The order is 
  // deterministic. You will always get the same devices in the same order
  //
  // Must be called before search()
  //oneWire.reset_search();
  // assigns the first address found to insideThermometer
  //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");

  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();

  // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
  sensors.setResolution(insideThermometer, 9);
 
  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(insideThermometer), DEC); 
  Serial.println();

  
}
コード例 #8
0
ファイル: Tester.cpp プロジェクト: hdo/arduino_panstamp
void setup(void)
{
  // start serial port
  Serial.begin(38400);
  delay(1000);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
  
  // Grab a count of devices on the wire
  numberOfDevices = sensors.getDeviceCount();
  
  // locate devices on the bus
  Serial.print("Locating devices...");
  
  Serial.print("Found ");
  Serial.print(numberOfDevices, DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  
  // Loop through each device, print out address
  for(int i=0;i<numberOfDevices; i++)
  {
    // Search the wire for address
    if(sensors.getAddress(tempDeviceAddress, i))
	{
		Serial.print("Found device ");
		Serial.print(i, DEC);
		Serial.print(" with address: ");
		printAddress(tempDeviceAddress);
		Serial.println();
		
		Serial.print("Setting resolution to ");
		Serial.println(TEMPERATURE_PRECISION, DEC);
		
		// set the resolution to TEMPERATURE_PRECISION bit (Each Dallas/Maxim device is capable of several different resolutions)
		sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);
		
		 Serial.print("Resolution actually set to: ");
		Serial.print(sensors.getResolution(tempDeviceAddress), DEC); 
		Serial.println();
	}else{
		Serial.print("Found ghost device at ");
		Serial.print(i, DEC);
		Serial.print(" but could not detect address. Check power and cabling");
	}
  }

}
コード例 #9
0
void setup()
{
   // Note: Ethernet shield uses digitial IO pins 10,11,12, and 13   
   Serial.begin(9600);
  
   Serial.println(version);
   Serial.println();
  
   // locate devices on the 1Wire bus
   Serial.print("Locating devices on 1Wire bus...");
   sensors.begin();
   int count = sensors.getDeviceCount();
   Serial.print("Found ");
   Serial.print( count );
   Serial.println(" devices on 1wire bus");

   // select the first sensor   
   for ( int i=0; i<count; i++ )
   {
      if ( sensors.getAddress(thermometer, i) ) 
      {
         Serial.print("1wire device ");
         Serial.print(i);
         Serial.print(" has address: ");
         printAddress(thermometer);
         Serial.println();
      }
      else
      {
         Serial.print("Unable to find address for 1wire device "); 
         Serial.println( i );
      }  
   }
  
   // if you want to use a particular sensor, you can hard code it here 
   if (0)
   { 
      DeviceAddress addr = { 0x10, 0xE4, 0xF1, 0xD2, 0x01, 0x08, 0x00, 0xBE };
      for (uint8_t i = 0; i < 8; i++)
      {
         thermometer[i] = addr[i];
      }
   }
  
   // show the addresses we found on the bus
   Serial.print("Using 1wire device: ");
   printAddress(thermometer);
   Serial.println();

   // set the resolution to 9 bit 
   sensors.setResolution(thermometer, 9);
  
   dhcpInit();
}
コード例 #10
0
ファイル: 5sparktemp.cpp プロジェクト: RobertNewkirk/particle
int regDeviceFunc(String command){
    if(command == "searchReg") {
        int regfound = 0;
        for(int i = 0; i < 100; i++) {

           if(EEPROM.read(i) == 0xFF ) {
                regfound++;
                Serial.print(i);
                Serial.print(" EEPROM ");
                Serial.println();
           } else {
               Serial.print(i);
               Serial.println(" EEPROM not matching");
           }
       }
       return regfound;
    }
    if(command != "searchReg" ) {
        int mindex = command.toInt();
        int setAddr = mindex * 8;
        Serial.print("the address for device ");
        Serial.print(mindex);
        sensor.getAddress(tempDeviceAddress, mindex);
        // Serial.print(" the size of the tempAddress is ");
       // Serial.print(arraySize(tempDeviceAddress));

        /* got address in array
        1.  run through eeprom and search for device
        2.  if no device is found find the available slot, return the location in eeprom
        3.  loop through the tempaddress and write it to the location.
        */
        //Serial.println(tempDeviceAddress[0], HEX); // Works prints 28

        //write the address at location 0 - 7
        for (uint8_t i = 0; i < 8; i++) {
            uint8_t writeLocation = i  + setAddr;
            EEPROM.write(writeLocation, tempDeviceAddress[i]);


        }






        return 2;

    }
}
コード例 #11
0
ファイル: endevor2.cpp プロジェクト: RobertNewkirk/particle
int queryDevices(String command) {

    if(command == "auto") {
    // sets and prints the device array
        for(int i=0; i < deviceCount; i++ ) {
            sensor.getAddress(deviceIndexArray[i], i);
            Serial.print("Device Index ");
            Serial.print(i);
            printAddress(deviceIndexArray[i]);
            Serial.print("\n");
        }
        Serial.print("----------------------------------\n");
        return 1;
    }

    if(command == "array" ) {
    // prints the device Array but does not set it
        Serial << "Display deviceIndexArray " << endl << "----------------------------------\n"  << endl;
        for ( int i=0; i < 5; i++ ) {
            Serial << "\n deviceIndexArray[" << i << "]: ";
            printAddress(deviceIndexArray[i]);

        }
        Serial <<  "\n----------------------------------\n" << endl;
        return 1;
    }

    if(command == "invert" ) {
      oled.command(INVERTDISPLAY);
        Serial << "normal display " << endl;
      return 1;
    }

    if(command == "normal" ) {
      Serial << "normal display " << endl;
      oled.command(NORMALDISPLAY);
      return 1;
    }


    if(command == "sysver" ) {
    Serial << "System Version " << System.version().c_str() << endl;
      return 1;
    }

    else return -1;

}
コード例 #12
0
ファイル: MexClk.cpp プロジェクト: eduardomdrs/rtc_therm_7seg
void setup()
{
	fsmState = EDIT_TIME_MODE;

	// initialize thermometer
	sensor.begin();
	sensor.setWaitForConversion(true);
	sensor.getAddress(devAddr, 0);
	sensor.requestTemperatures();
	tempInCelsius = (int) (sensor.getTempC(devAddr)*10);

	// initialize buttons
	buttonA.setClickTicks(250);
	buttonA.setPressTicks(600);
	buttonA.attachLongPressStart(longPressA);
	buttonA.attachClick(singleClickA);
	buttonA.attachDoubleClick(doubleClickA);

	buttonB.setClickTicks(250);
	buttonB.setPressTicks(600);
	buttonB.attachClick(singleClickB);
	buttonB.attachDoubleClick(doubleClickB);
	buttonB.attachLongPressStart(longPressB);

	// initialize serial
	Serial.begin(115200);

	// initialize rtc
	
	setSyncProvider(RTC.get);
	setSyncInterval(1);
	if(timeStatus()!= timeSet) 
	{
		Serial.println("Unable to sync with the RTC");
		fsmState = ERROR_MODE;
	} else
	{
		Serial.println("RTC has set the system time"); 
	}
	
	// default alarm settings, 08:30, disabled
	pinMode(ALARM_PIN, INPUT_PULLUP);
}