KeyError: 'first_sketch_line'

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
rnd
Posts: 4
Joined: 05 Aug 2016 19:26

KeyError: 'first_sketch_line'

Post by rnd »

Anyone that can explain this error to me?

Code: Select all

Arduino: 1.6.5 (Linux), Board: "Z-Wave>ME Z-Uno, Europe, Disabled, Disabled"

Build options changed, rebuilding all
Using library ZUNO_DS18B20 in folder: /home/m/.arduino15/packages/Z-Uno/hardware/zw8051/2.0.6/libraries/ZUNO_DS18B20 (legacy)

/home/m/.arduino15/packages/Z-Uno/tools/zuno_toolchain/00.08.10/zuno_toolchain/compiler build /tmp/build5515980077194694846.tmp/MultiOneWire.cpp -r /home/m/.arduino15/packages/Z-Uno/hardware/zw8051/2.0.6 

	************* Building Arduino Sketch *************
	/tmp/build5515980077194694846.tmp/MultiOneWire.cpp
	***************************************************

Preprocessing file: /tmp/build5515980077194694846.tmp/Print.cpp with SDCPP... 
Compiling /tmp/build5515980077194694846.tmp/Print_sdcpp_.cpp ...
Preprocessing file: /tmp/build5515980077194694846.tmp/Stream.cpp with SDCPP... 
Compiling /tmp/build5515980077194694846.tmp/Stream_sdcpp_.cpp ...
Preprocessing file: /tmp/build5515980077194694846.tmp/HardwareSerial.cpp with SDCPP... 
Compiling /tmp/build5515980077194694846.tmp/HardwareSerial_sdcpp_.cpp ...
Preprocessing file: /tmp/build5515980077194694846.tmp/HLCore.cpp with SDCPP... 
Compiling /tmp/build5515980077194694846.tmp/HLCore_sdcpp_.cpp ...
Preprocessing file: /tmp/build5515980077194694846.tmp/ZUNO_OneWire.cpp with SDCPP... 
Compiling /tmp/build5515980077194694846.tmp/ZUNO_OneWire_sdcpp_.cpp ...
Preprocessing file: /tmp/build5515980077194694846.tmp/ZUNO_DS18B20.cpp with SDCPP... 
Compiling /tmp/build5515980077194694846.tmp/ZUNO_DS18B20_sdcpp_.cpp ...
Preprocessing file: /tmp/build5515980077194694846.tmp/_MultiOneWire.cpp with SDCPP... 
Compiling /tmp/build5515980077194694846.tmp/_MultiOneWire_sdcpp_.cpp ...
MultiOneWire.ino:54:20:warning:conversion from string literal to 'char *' is deprecated
MultiOneWire.ino:68:19:warning:conversion from string literal to 'char *' is deprecated
MultiOneWire.ino:70:19:warning:conversion from string literal to 'char *' is deprecated
MultiOneWire.ino:74:22:warning:conversion from string literal to 'char *' is deprecated
Exception:'first_sketch_line'
(<type 'exceptions.KeyError'>, '<string>', 235)
MultiOneWire.ino:78:19:warning:conversion from string literal to 'char *' is deprecated['__cxx__Stream__method__println020a11', '__cxx__Stream__method__readBytesUntil030dp0d08', '__cxx__Stream__method__clearWriteError00', '__cxx__Stream__method__print010d', '__cxx__Print__method__printFloat021505', '__cxx__Stream__method__readBytes02p0508', '__cxx__HardwareSerial__method__write0105', '__cxx__HardwareSerial__method__find010d', '__cxx__DS18B20Sensor__init01prOneWire', '__cxx__OneWire__method__read00', '__cxx__Print__method__print020a11', '__cxx__HardwareSerial__method__write0109', '__cxx__HardwareSerial__method__available00', '__cxx__Stream__method__print020511', '__cxx__HardwareSerial__method__parseInt010d', '__cxx__Stream__method__println021511', '__cxx__Stream__method__printNumber020a05', '__cxx__HardwareSerial__method__printByteArr03p050505', '__cxx__Stream__method__findUntil02p05p0d', '__cxx__HardwareSerial__method__setWriteError0111', '__cxx__Stream__method__find02p0508', '__cxx__Stream__method__print020a11', '__cxx__HardwareSerial__method__find02p0d08', '__cxx__Stream__method__print021211', '__cxx__Print__method__print01p0d', '__cxx__HardwareSerial__method__write010a', '__cxx__Stream__method__println010d', '__cxx__HardwareSerial__method__write0112', '__cxx__HardwareSerial__method__write0111', '__cxx__Stream__method__findUntil04p0d08p0d08', '__cxx__Stream__method__println020911', '__cxx__Stream__method__readBytesUntil030dp0508', '__cxx__Print__method__setWriteError0111', '__cxx__Print__method__printNumber020a05', '__cxx__Print__method__println021211', '__cxx__Stream__init00', '__cxx__HardwareSerial__init0105', '__cxx__Print__method__print010d', '__cxx__Stream__method__println021111', '__cxx__Stream__method__print01p0d', '__cxx__HardwareSerial__method__parseFloat010d', '__cxx__Stream__method__println021211', '__cxx__Print__method__println020511', '__cxx__HardwareSerial__method__println00', '__cxx__HardwareSerial__method__flush00', '__cxx__HardwareSerial__method__find02p0508', '__cxx__Stream__method__println021611', '__cxx__Print__method__println021111', '__cxx__Stream__method__getWriteError00', '__cxx__HardwareSerial__method__peekNextDigit00', '__cxx__HardwareSerial__method__print020511', '__cxx__HardwareSerial__method__find01p0d', '__cxx__Print__method__println021511', '__cxx__Stream__method__println020511', '__cxx__HardwareSerial__method__printFloat021505', '__cxx__Stream__method__available00', '__cxx__Print__method__println021611', '__cxx__Stream__method__printByteArr03p050505', '__cxx__Print__method__println00', '__cxx__Print__method__println010d', '__cxx__HardwareSerial__method__setTimeout010a', '__cxx__Print__method__getWriteError00', '__cxx__Print__method__write02p0508', '__cxx__Stream__method__parseFloat00', '__cxx__HardwareSerial__method__readBytesUntil030dp0508', '__cxx__HardwareSerial__method__getWriteError00', '__cxx__HardwareSerial__method__print010d', '__cxx__HardwareSerial__method__println021511', '__cxx__Stream__method__findMulti02prMultiTarget11', '__cxx__HardwareSerial__method__print01p0d', '__cxx__Stream__method__findUntil02p0dp0d', '__cxx__HardwareSerial__method__readBytes02p0d08', '__cxx__HardwareSerial__method__peek00', '__cxx__Stream__method__println00', '__cxx__HardwareSerial__method__println021611', '__cxx__Print__init00', '__cxx__HardwareSerial__method__find01p05', '__cxx__HardwareSerial__method__timedPeek00', '__cxx__Print__method__printByteArr03p050505', '__cxx__Stream__method__write02p0508', '__cxx__Stream__method__setTimeout010a', '__cxx__OneWire__init0105', '__cxx__Stream__method__setWriteError0111', '__cxx__Stream__method__find01p05', '__cxx__Print__method__println020a11', '__cxx__HardwareSerial__method__println010d', '__cxx__Stream__method__parseFloat010d', '__cxx__HardwareSerial__method__parseInt00', '__cxx__Print__method__write0105', '__cxx__Stream__method__find02p0d08', '__cxx__Stream__method__flush00', '__cxx__HardwareSerial__method__findUntil04p0d08p0d08', '__cxx__HardwareSerial__method__parseFloat00', '__cxx__OneWire__method__reset00', '__cxx__OneWire__method__crc802p0505', '__cxx__HardwareSerial__method__write02p0508', '__cxx__Print__method__print020911', '__cxx__HardwareSerial__method__println021211', '__cxx__Print__method__println020911', '__cxx__Stream__method__parseInt00', '__cxx__Stream__method__timedRead00', '__cxx__HardwareSerial__method__findMulti02prMultiTarget11', '__cxx__Stream__method__read00', '__cxx__OneWire__method__skip00', '__cxx__HardwareSerial__method__println020a11', '__cxx__Print__method__print021211', '__cxx__Stream__method__print020911', '__cxx__Print__method__println01p0d', '__cxx__Stream__method__readBytes02p0d08', '__cxx__Stream__method__peek00', '__cxx__HardwareSerial__method__end00', '__cxx__HardwareSerial__method__printNumber020a05', '__cxx__HardwareSerial__method__readBytes02p0508', '__cxx__DS18B20Sensor__method__scanAloneSensor01p05', '__cxx__Print__method__print021511', '__cxx__HardwareSerial__method__findUntil02p05p0d', '__cxx__Print__method__print020511', '__cxx__HardwareSerial__method__read00', '__cxx__Print__method__print021611', '__cxx__DS18B20Sensor__method__getTemperature01p05', '__cxx__HardwareSerial__method__println020511', '__cxx__HardwareSerial__method__print021211', '__cxx__Stream__method__find01p0d', '__cxx__HardwareSerial__method__print021611', '__cxx__HardwareSerial__method__print021511', '__cxx__OneWire__method__depower00', '__cxx__Print__method__print021111', '__cxx__Stream__method__timedPeek00', '__cxx__Stream__method__peekNextDigit00', '__cxx__HardwareSerial__method__print020911', '__cxx__OneWire__method__write020505', '__cxx__OneWire__method__select01p05', '__cxx__HardwareSerial__method__timedRead00', '__cxx__Stream__method__parseInt010d', '__cxx__HardwareSerial__method__print021111', '__cxx__HardwareSerial__method__begin00', '__cxx__Stream__method__println01p0d', '__cxx__Stream__method__print021611', '__cxx__Stream__method__printFloat021505', '__cxx__HardwareSerial__method__println020911', '__cxx__Stream__method__print021511', '__cxx__Print__method__clearWriteError00', '__cxx__OneWire__method__readROM01p05', '__cxx__Stream__method__write0105', '__cxx__DS18B20Sensor__method__getTempC10001p05', '__cxx__Stream__method__find010d', '__cxx__HardwareSerial__method__readBytesUntil030dp0d08', '__cxx__HardwareSerial__method__print020a11', '__cxx__HardwareSerial__method__println021111', '__cxx__HardwareSerial__method__clearWriteError00', '__cxx__HardwareSerial__method__begin010a', '__cxx__Stream__method__print021111', '__cxx__HardwareSerial__method__println01p0d', '__cxx__HardwareSerial__method__findUntil02p0dp0d']Traceback (most recent call last):
  File "<string>", line 235, in buildFunc
  File "/tmp/zuno-packager/build/zuno_toolchain-00.08.10-linux64/uCxx.py", line 4824, in compileArduinoSketch
  File "/tmp/zuno-packager/build/zuno_toolchain-00.08.10-linux64/uCxx.py", line 4658, in compileCPPPhase
  File "/tmp/zuno-packager/build/zuno_toolchain-00.08.10-linux64/uCxx.py", line 4613, in advancedCompileCXX
  File "/tmp/zuno-packager/build/zuno_toolchain-00.08.10-linux64/uCxx.py", line 3785, in CompileCXX
  File "/tmp/zuno-packager/build/zuno_toolchain-00.08.10-linux64/uCxx.py", line 4416, in compilerPrintError
KeyError: 'first_sketch_line'
/home/m/.arduino15/packages/Z-Uno/tools/zuno_toolchain/00.08.10/zuno_toolchain/compiler returned 2
Error compiling.
Sketch looks like this

Code: Select all

// Multiple temperature sensors 

#include <ZUNO_DS18B20.h>

// DS18B20 pin connections 
#define PIN_DS18B20_1 5
#define PIN_DS18B20_2 6
#define PIN_DS18B20_3 7
#define PIN_DS18B20_4 8
#define PIN_DS18B20_5 9
#define PIN_DS18B20_6 10
#define PIN_DS18B20_7 11
#define PIN_DS18B20_8 12

OneWire ow[8] = 
{
  OneWire(PIN_DS18B20_1),
  OneWire(PIN_DS18B20_2),
  OneWire(PIN_DS18B20_3),
  OneWire(PIN_DS18B20_4),
  OneWire(PIN_DS18B20_5),
  OneWire(PIN_DS18B20_6),
  OneWire(PIN_DS18B20_7),
  OneWire(PIN_DS18B20_8)
};

DS18B20Sensor ds[8] =
{
  DS18B20Sensor(&ow[0]),
  DS18B20Sensor(&ow[1]),
  DS18B20Sensor(&ow[2]),
  DS18B20Sensor(&ow[3]),
  DS18B20Sensor(&ow[4]),
  DS18B20Sensor(&ow[5]),
  DS18B20Sensor(&ow[6]),
  DS18B20Sensor(&ow[7])
}; 

int temp[8]; 

ZUNO_SETUP_CHANNELS(
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp0),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp1),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp2),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp3),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp4),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp5),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp6),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp7)
);

void setup() {
    Serial.begin();
    Serial.println("start");  
}

void loop() 
{
  float temperature;
  byte addr[8];
  
  for (int x=0; x<8; x++)
  {
     ds[x].scanAloneSensor(addr);
     temperature = ds[x].getTemperature(addr);
     temp[x]=int(temperature*100);

     Serial.print("Sensor ");
     Serial.print(x);
     Serial.print(" address is: ");
     for (int i = 0; i < 8; i++)
     {
        Serial.print(addr[i], HEX);
        Serial.print(" ");
     }

     Serial.println();
     Serial.print("Temperature: ");
     Serial.println(temperature);
     Serial.println();
  }
    
  zunoSendReport(1);     
  delay(30000);
}

word getterTemp0() 
{
    return temp[0];
}

word getterTemp1() 
{
    return temp[1];
}

word getterTemp2() 
{
    return temp[2];
}

word getterTemp3() 
{
    return temp[3];
}

word getterTemp4() 
{
    return temp[4];
}

word getterTemp5() 
{
    return temp[5];
}

word getterTemp6() 
{
    return temp[6];
}

word getterTemp7() 
{
    return temp[7];
}
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: KeyError: 'first_sketch_line'

Post by p0lyg0n1 »

First of all currently (v 0.8.10) uCxx doesn't support constructors inside array init list.
But you don't need it here. You can connect all sensors to one pin which you use for 1-wire bus, because the major feature of it is addressing. Here is an example of communication with 2 sensors:
// Multiple temperature sensors

#include <ZUNO_DS18B20.h>

// DS18B20 pin connections
#define PIN_OW 9 // this is s_pin number and it have to be in range[9;16]


// We can connect a lot of 1-wire devices to 1-pin
// Because 1-wire is BUS with addresses
OneWire ow(PIN_OW);
// We need only one sensor in one moment of time to read it, so just
// create one object of it
DS18B20Sensor sen18b20(&ow);
// Currrently uCxx (v 0.810) doesn't support an array of constructed object
// But you can use an array of pointers to object
// For example in terms of 18b20:
// DS18B20Sensor sen1(&ow);
// DS18B20Sensor sen2(&ow);
// DS18B20Sensor * sensors[] = {&sen1, &sen2};

// Anyway you don't need it ^ here :)

// Instead of it we have to know adresses of all sensors that you connect to your 1-Wire bus.
// You can detect it if you connect it alone to the BUS one by one and record them addresses
// use scanAloneSensor() it returns 8-byte unique address of sensor connected to the BUS and fill sensor_addresses. This addresses is unique for any 1-wire device.

#define NUMBER_OF_SENSORS 2
#define ADDR_SIZE 8


byte sensor_addresses[NUMBER_OF_SENSORS][ADDR_SIZE] = {{0x28, 0x11, 0x5F, 0x9B, 0x06, 0x00, 0x00, 0x2C},
{0x28, 0xFF, 0x2B, 0x45, 0x4C, 0x04, 0x00, 0x10}};

int temp[NUMBER_OF_SENSORS];

ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp0),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp1));

void setup() {
Serial.begin();
Serial.println("start");
}

void loop()
{
// use byte instead of int to reduce code size
for (byte i=0; i<NUMBER_OF_SENSORS; i++)
{
// Use fixed point math
// get temperature of sensor with address sensor_addresses
temp = sen18b20.getTempC100(sensor_addresses);

Serial.print("Sensor ");
Serial.print(i);
Serial.print(" address is: ");
for (byte j = 0; j < ADDR_SIZE; j++)
{
Serial.print(sensor_addresses[j], HEX);
Serial.print(" ");
}

Serial.println();
Serial.print("Temperature: ");
Serial.println(temp/100.0);
Serial.println();

// Sending report to the right channel
zunoSendReport(1 + i);
}


delay(30000);
}

word getterTemp0()
{
return temp[0];
}

word getterTemp1()
{
return temp[1];
}


You can extend it for 8-sensors. The only thing you need is sensor's unique address.
rnd
Posts: 4
Joined: 05 Aug 2016 19:26

Re: KeyError: 'first_sketch_line'

Post by rnd »

Thank you for taking the time to help me with this.

I understand this is how 1-wire works but manually adding addresses to sketches and keeping track of which sensor is which creates extra work compared to one sensor per pin. (The DS1825 is great for running multiple sensors on one pin). But in this instance one sensor per pin would be my preferred way.

So I tried removing the arrays of constructors but still get the error.

Code: Select all

Using library ZUNO_DS18B20 in folder: /home/magnus/.arduino15/packages/Z-Uno/hardware/zw8051/2.0.6/libraries/ZUNO_DS18B20 (legacy)

/home/magnus/.arduino15/packages/Z-Uno/tools/zuno_toolchain/00.08.10/zuno_toolchain/compiler build /tmp/build6539141314778572679.tmp/MultiOneWire.cpp -r /home/magnus/.arduino15/packages/Z-Uno/hardware/zw8051/2.0.6 

	************* Building Arduino Sketch *************
	/tmp/build6539141314778572679.tmp/MultiOneWire.cpp
	***************************************************

Preprocessing file: /tmp/build6539141314778572679.tmp/Print.cpp with SDCPP... 
Compiling /tmp/build6539141314778572679.tmp/Print_sdcpp_.cpp ...
Preprocessing file: /tmp/build6539141314778572679.tmp/Stream.cpp with SDCPP... 
Compiling /tmp/build6539141314778572679.tmp/Stream_sdcpp_.cpp ...
Preprocessing file: /tmp/build6539141314778572679.tmp/HardwareSerial.cpp with SDCPP... 
Compiling /tmp/build6539141314778572679.tmp/HardwareSerial_sdcpp_.cpp ...
Preprocessing file: /tmp/build6539141314778572679.tmp/HLCore.cpp with SDCPP... 
Compiling /tmp/build6539141314778572679.tmp/HLCore_sdcpp_.cpp ...
Preprocessing file: /tmp/build6539141314778572679.tmp/ZUNO_OneWire.cpp with SDCPP... 
Compiling /tmp/build6539141314778572679.tmp/ZUNO_OneWire_sdcpp_.cpp ...
Preprocessing file: /tmp/build6539141314778572679.tmp/ZUNO_DS18B20.cpp with SDCPP... 
Compiling /tmp/build6539141314778572679.tmp/ZUNO_DS18B20_sdcpp_.cpp ...
Preprocessing file: /tmp/build6539141314778572679.tmp/_MultiOneWire.cpp with SDCPP... 
Compiling /tmp/build6539141314778572679.tmp/_MultiOneWire_sdcpp_.cpp ...
MultiOneWire.ino:49:20:warning:conversion from string literal to 'char *' is deprecatedTraceback (most recent call last):
  File "<string>", line 235, in buildFunc
  File "/tmp/zuno-packager/build/zuno_toolchain-00.08.10-linux64/uCxx.py", line 4824, in compileArduinoSketch
  File "/tmp/zuno-packager/build/zuno_toolchain-00.08.10-linux64/uCxx.py", line 4658, in compileCPPPhase
  File "/tmp/zuno-packager/build/zuno_toolchain-00.08.10-linux64/uCxx.py", line 4613, in advancedCompileCXX
Exception:'first_sketch_line'
(<type 'exceptions.KeyError'>, '<string>', 235)
  File "/tmp/zuno-packager/build/zuno_toolchain-00.08.10-linux64/uCxx.py", line 3785, in CompileCXX
  File "/tmp/zuno-packager/build/zuno_toolchain-00.08.10-linux64/uCxx.py", line 4416, in compilerPrintError
KeyError: 'first_sketch_line'
/home/magnus/.arduino15/packages/Z-Uno/tools/zuno_toolchain/00.08.10/zuno_toolchain/compiler returned 2
Error compiling.

Code: Select all

// Multiple temperature sensors 

#include <ZUNO_DS18B20.h>

// DS18B20 pin connections 
#define PIN_DS18B20_1 5
#define PIN_DS18B20_2 6
#define PIN_DS18B20_3 7
#define PIN_DS18B20_4 8
#define PIN_DS18B20_5 9
#define PIN_DS18B20_6 10
#define PIN_DS18B20_7 11
#define PIN_DS18B20_8 12

OneWire ow1(PIN_DS18B20_1);
OneWire ow2(PIN_DS18B20_2);
OneWire ow3(PIN_DS18B20_3);
OneWire ow4(PIN_DS18B20_4);
OneWire ow5(PIN_DS18B20_5);
OneWire ow6(PIN_DS18B20_6);
OneWire ow7(PIN_DS18B20_7);
OneWire ow8(PIN_DS18B20_8);

DS18B20Sensor ds1(&ow1);
DS18B20Sensor ds2(&ow2);
DS18B20Sensor ds3(&ow3);
DS18B20Sensor ds4(&ow4);
DS18B20Sensor ds5(&ow5);
DS18B20Sensor ds6(&ow6);
DS18B20Sensor ds7(&ow7);
DS18B20Sensor ds8(&ow8);

//DS18B20Sensor * sensors[] = {&ds1, &ds2, &ds3, &ds4, &ds5, &ds6, &ds7, &ds8};
int temp[8]; 

ZUNO_SETUP_CHANNELS(
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp0),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp1),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp2),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp3),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp4),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp5),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp6),
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp7)
);

void setup() {
    Serial.begin();
    Serial.println("start");  
}

void loop() 
{
  float temperature;
  byte addr[8];

  ds1.scanAloneSensor(addr);
  temp[0] = ds1.getTempC100(addr);
  zunoSendReport(1);
  
//  for (byte x=0; x<8; x++)
//  {
//     sensors[x]->scanAloneSensor(addr);
//     temp[x] = sensors[x]->getTempC100(addr);
//
//     Serial.print("Sensor ");
//     Serial.print(x);
//     Serial.print(" address is: ");
//     for (int i = 0; i < 8; i++)
//     {
//        Serial.print(addr[i], HEX);
//        Serial.print(" ");
//     }
//
//     Serial.println();
//     Serial.print("Temperature: ");
//     Serial.println(temperature);
//     Serial.println();
//
//     zunoSendReport(x + 1);
//  }     
  delay(30000);
}

word getterTemp0() 
{
    return temp[0];
}

word getterTemp1() 
{
    return temp[1];
}

word getterTemp2() 
{
    return temp[2];
}

word getterTemp3() 
{
    return temp[3];
}

word getterTemp4() 
{
    return temp[4];
}

word getterTemp5() 
{
    return temp[5];
}

word getterTemp6() 
{
    return temp[6];
}

word getterTemp7() 
{
    return temp[7];
}

User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

Re: KeyError: 'first_sketch_line'

Post by PoltoS »

Note that 1-wire can work only on fast pins 9-16.
rnd
Posts: 4
Joined: 05 Aug 2016 19:26

Re: KeyError: 'first_sketch_line'

Post by rnd »

Thank you! Now it compiles.
n0ir
Posts: 21
Joined: 17 Nov 2016 16:17

Re: KeyError: 'first_sketch_line'

Post by n0ir »

p0lyg0n1 wrote:First of all currently (v 0.8.10) uCxx doesn't support constructors inside array init list.
But you don't need it here. You can connect all sensors to one pin which you use for 1-wire bus, because the major feature of it is addressing. Here is an example of communication with 2 sensors:
Hi!

I tried to use the code provided to connect two DS18B20 sensors to my Z-Uno. I have previously used my Uno to find the ID of the sensors and pasted them in the code.

However, I only get one temperature sensor device in my Vera, together with two "_Generic IO 1"-devices. The temperature sensor doesn't show temperature.
2016-11-23.png
2016-11-23.png (23.3 KiB) Viewed 9175 times
I have connected the same setup to my Uno and checked the values from the DS18B20. They seem to work.

@rnd: Did you get your setup with one DS18B20 per pin to work? Could you share the sketch?

Code: Select all

// Multiple temperature sensors 

#include <ZUNO_DS18B20.h>

// DS18B20 pin connections 
#define PIN_OW 9 // this is s_pin number and it have to be in range[9;16]


// We can connect a lot of 1-wire devices to 1-pin
// Because 1-wire is BUS with addresses
OneWire ow(PIN_OW);
// We need only one sensor in one moment of time to read it, so just
// create one object of it 
DS18B20Sensor sen18b20(&ow);
// Currrently uCxx (v 0.810) doesn't support an array of constructed object
// But you can use an array of pointers to object
// For example in terms of 18b20:
// DS18B20Sensor sen1(&ow);
// DS18B20Sensor sen2(&ow);
// DS18B20Sensor * sensors[] = {&sen1, &sen2};

// Anyway you don't need it ^ here :) 

// Instead of it we have to know adresses of all sensors that you connect to your 1-Wire bus.
// You can detect it if you connect it alone to the BUS one by one and record them addresses
// use scanAloneSensor() it returns 8-byte unique address of sensor connected to the BUS and fill sensor_addresses. This addresses is unique for any 1-wire device. 

#define NUMBER_OF_SENSORS 2
#define ADDR_SIZE 8


byte sensor_addresses[NUMBER_OF_SENSORS][ADDR_SIZE] = {
{0x28, 0x1C, 0xD7, 0x3B, 0x05, 0x00, 0x00, 0xDE},
{0x28, 0x43, 0x9C, 0x3B, 0x05, 0x00, 0x00, 0x4D}
};

int temp[NUMBER_OF_SENSORS]; 

ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp0),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp1));

void setup() {
Serial.begin();
Serial.println("start"); 
}

void loop() 
{
// use byte instead of int to reduce code size
for (byte i=0; i<NUMBER_OF_SENSORS; i++)
{
// Use fixed point math
// get temperature of sensor with address sensor_addresses[i] 
temp[i] = sen18b20.getTempC100(sensor_addresses[i]);

Serial.print("Sensor ");
Serial.print(i);
Serial.print(" address is: ");
for (byte j = 0; j < ADDR_SIZE; j++)
{
Serial.print(sensor_addresses[i][j], HEX);
Serial.print(" ");
}

Serial.println();
Serial.print("Temperature: ");
Serial.println(temp[i]/100.0);
Serial.println();

// Sending report to the right channel
zunoSendReport(1 + i); 
}


delay(30000);
}

word getterTemp0() 
{
return temp[0];
}

word getterTemp1() 
{
return temp[1];
}
michap
Posts: 437
Joined: 26 Mar 2013 10:35
Contact:

Re: KeyError: 'first_sketch_line'

Post by michap »

Do you get the right values in debug window?

Serial.print("Temperature: ");
Serial.println(temp/100.0);

Michael
michap
Posts: 437
Joined: 26 Mar 2013 10:35
Contact:

Re: KeyError: 'first_sketch_line'

Post by michap »

Hi,
with current compiler version it will not work as described by p0lyg0n1.
(seems to be any issue with Multi-Dimensional Arrays)
I made a simple sketch - tested it... You can try and modify - add sensors etc.

Code: Select all

// Multiple temperature sensors

#include <ZUNO_DS18B20.h>

// DS18B20 pin connections
#define PIN_OW 9 // this is s_pin number and it have to be in range[9;16]

// We can connect a lot of 1-wire devices to 1-pin
// Because 1-wire is BUS with addresses
OneWire ow(PIN_OW);
// We need only one sensor in one moment of time to read it, so just
// create one object of it
DS18B20Sensor sen18b20(&ow);
// Instead of it we have to know adresses of all sensors that you connect to your 1-Wire bus.
// You can detect it if you connect it alone to the BUS one by one and record them addresses
// use scanAloneSensor() it returns 8-byte unique address of sensor connected to the BUS and fill sensor_addresses. This addresses is unique for any 1-wire device.

#define NUMBER_OF_SENSORS 2

byte sensor_addr1[8] = {0x28, 0x84, 0xAE, 0x57, 0x06, 0x00, 0x00, 0x36};
byte sensor_addr2[8] = {0x28, 0x24, 0x26, 0x57, 0x06, 0x00, 0x00, 0x9F};

int temp[NUMBER_OF_SENSORS];

ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp0),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp1));

void setup() {
Serial.begin();
Serial.println("start");
}

void loop()
{
// Use fixed point math
// get temperature of sensor with address sensor_addr
temp[0] = sen18b20.getTempC100(sensor_addr1);
temp[1] = sen18b20.getTempC100(sensor_addr2);

Serial.print("Sensor 1 Temperature ");
Serial.println(temp[0]/100.0);
Serial.println();

Serial.print("Sensor 2 Temperature ");
Serial.println(temp[1]/100.0);
Serial.println();

// Sending report to the right channel
zunoSendReport(1);
zunoSendReport(2);

delay(30000);
}

word getterTemp0()
{
return temp[0];
}

word getterTemp1()
{
return temp[1];
}
I hope it help

Michael
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: KeyError: 'first_sketch_line'

Post by p0lyg0n1 »

Hi,
Yes you right there is a problem with a compiler.
It makes sizes of multi-idimension arrays in wrong order.
There is a small workaround
you can replace

Code: Select all

byte sensor_addresses[NUMBER_OF_SENSORS][ADDR_SIZE] = {
{0x28, 0x1C, 0xD7, 0x3B, 0x05, 0x00, 0x00, 0xDE},
{0x28, 0x43, 0x9C, 0x3B, 0x05, 0x00, 0x00, 0x4D}
};
with

Code: Select all

byte sensor_addresses[][] = {
{0x28, 0x1C, 0xD7, 0x3B, 0x05, 0x00, 0x00, 0xDE},
{0x28, 0x43, 0x9C, 0x3B, 0x05, 0x00, 0x00, 0x4D}
};
michap
Posts: 437
Joined: 26 Mar 2013 10:35
Contact:

Re: KeyError: 'first_sketch_line'

Post by michap »

@p0lyg0n1: This I already tried before ;)
I get then:

Code: Select all

uCxx returned error code:1

array has incomplete element type 'BYTE []'
Michael
Post Reply