assigning to an array from an initializer list (after a ubuntu change version)

Hello guys,

A very strange problem.
I had a 12.04 ubuntu, Arduino V1.0 and this code worked perfectly :

int chaine[2];
void setup() {
chaine={1,2};
}
void loop(){}

Then I've installed ubuntu 13.10, arduino V1.0.5 and the same code gives : assigning to an array from an initializer list

I removed the v1.0.5 arduino for v1.0 but still the same error on ubuntu 13.10

I have no explanation at all !!???

regards

This isn't legal:

chaine={1,2};

You can only initialize an array when you declare it. Hard to say how it could have compiled previously. Easy enough to fix by moving the ={1,2}; to the declaration though.

mdeudon:
I have no explanation at all !!???

I do. You are mistaken in what code you were running before. That code, as shown, is not legal C code. It can't have ever worked, and it will never work.

You can only assign the contents of an array when you declare the array. At any other time you have to manipulate it one element at a time. The following is legal:

int chaine[2]={1,2};
void setup() {}
void loop(){}

As is this:

int chaine[2];
void setup() {
  chaine[0] = 1;
  chaine[1] = 2;
}
void loop() {}

Same problem i am also facing, i couldn't solve it.

code:

#include <avr/pgmspace.h>

int sensors[5] = {1,2,3,4,5};

int sensor1, sensor2, sensor3, sensor4, sensor5;

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

void loop(){

sensor1 = analogRead(0);
sensor2 = analogRead(1);
sensor3 = analogRead(2);
sensor4 = analogRead(3);
sensor5 = analogRead(4);
delay(600);
sensors = {sensor1, sensor2, sensor3, sensor4, sensor5};
Serial.println (sensors);
}

Error:
Arduino: 1.6.5 (Windows 7), TD: 1.25, Board: "Arduino/Genuino Uno"

measurement.ino: In function 'void loop()':
measurement:21: error: assigning to an array from an initializer list
assigning to an array from an initializer list

read reply #2 above

int sensorValue[5];

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

void loop() {
  for (byte idx = 0; idx < 5; idx++) {
    sensorValue[idx] = analogRead(idx);
    Serial.print(F("sensorValue["));
    Serial.print(idx);
    Serial.print(F("] = "));
    Serial.print(sensorValue[idx]);
    Serial.print(F(" "));
  }
  Serial.println();
  delay(500);
}

Hi, Whandall.

Your code is good and uploaded well, but i need the output data as output of the above mentioned program.
It is leading to some more errors as the function i declared accepts only (int*)

Could you suggest me to get rid of above error for my code.

harithota20:
It is leading to some more errors as the function i declared accepts only (int*)

Your original post (#3) does not contain a function that accepts an int pointer. Please provide complete code.

harithota20:
Could you suggest me to get rid of above error for my code.

As said, please provide the complete code; and for this, also provide the complete (set of) error messages.

int sensors[5] = {1,2,3,4,5};

What is this supposed to be? An array of pin numbers? No, it can't be? An array of sensor readings initialized with dummy values?

Please download library for Support Vector Machine Library from below link.

I would like to read 5 sensors data and i need to classify.

"measurement.ino" is meant for reading the data from arduino, if i try to implement that program it is not accepting the output arrays of analog readings.

harithota20:
Please download library for Support Vector Machine Library from below link.

GitHub - radzilu/Arduino-SVM

I would like to read 5 sensors data and i need to classify.

"measurement.ino" is meant for reading the data from arduino, if i try to implement that program it is not accepting the output arrays of analog readings.

Quit the mumbo-jumbo - post your code (use code tags) and post the exact error message you're seeing.

:slight_smile:
then this is without that numbo-jumbo....AWOL.

#include <avr/pgmspace.h>

// In this section you should implement the handling of your sensor data, which you would like to classify.
// and an example would be:

int sensors[5] = {0};

int sensor1, sensor2, sensor3, sensor4, sensor5;

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

void loop(){

sensor1 = analogRead(0);
sensor2 = analogRead(1);
sensor3 = analogRead(2);
sensor4 = analogRead(3);
sensor5 = analogRead(4);
delay(600);
sensors = {sensor1, sensor2, sensor3, sensor4, sensor5};
svm_predict(sensors);
}

Error Message:

Arduino: 1.6.5 (Windows 7), TD: 1.25, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz optimized (overclock), US English"

In file included from sketch_svm.ino:1:0:
sketch_svm.ino: In function 'void svm_predict(int*)':
C:\Program Files\Arduino\hardware\teensy\avr\cores\teensy3/avr/pgmspace.h:78:61: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
#define pgm_read_word(addr) (*(const unsigned short )(addr))
^
sketch_svm.ino:59:35: note: in expansion of macro 'pgm_read_word'
C:\Program Files\Arduino\hardware\teensy\avr\cores\teensy3/avr/pgmspace.h:78:61: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
#define pgm_read_word(addr) (
(const unsigned short )(addr))
^
sketch_svm.ino:60:35: note: in expansion of macro 'pgm_read_word'
C:\Program Files\Arduino\hardware\teensy\avr\cores\teensy3/avr/pgmspace.h:78:61: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
#define pgm_read_word(addr) (
(const unsigned short )(addr))
^
sketch_svm.ino:61:35: note: in expansion of macro 'pgm_read_word'
C:\Program Files\Arduino\hardware\teensy\avr\cores\teensy3/avr/pgmspace.h:78:61: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
#define pgm_read_word(addr) (
(const unsigned short *)(addr))
^
sketch_svm.ino:62:34: note: in expansion of macro 'pgm_read_word'
measurement.ino: In function 'void loop()':
measurement:22: error: assigning to an array from an initializer list
assigning to an array from an initializer list

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

You still don't get the fact that you can not do the below

  sensors = {sensor1, sensor2, sensor3, sensor4, sensor5};

Why don't you use an array in a way it is supposed to be used? Maybe reading a book on the C basics will help :wink:

#include <avr/pgmspace.h>

// In this section you should implement the handling of your sensor data, which you would like to classify.
// and an example would be:

int sensors[5];

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

void loop() {

  sensors[0] = analogRead(0);
  sensors[1] = analogRead(1);
  sensors[2] = analogRead(2);
  sensors[3] = analogRead(3);
  sensors[4] = analogRead(4);
  delay(600);
  svm_predict(sensors);
}

Your code is more than likely also missing an include statement in the beginning and hence the compiler does not know svm_predict.

PS
Next time, please post code between [code] and [/code] and not in quotes; makes it easier to copy. Same applies for error messages. Thank you.

Note: I did not look at other errors as I did not get them with the above code; compiled with IDE 1.6.6 on Windows 8.

:slight_smile: Thank you for your suggestions. you are right, i am dumb when it comes to programming...

I didn't understand why this recent versions of arduino are throwing more errors than previous version. :o

Please state which version of the Arduino IDE your code allegedly worked with.

I am not blaming the recent versions but
i was using arduino 1.6.0 and installed many third party libraries.
I upgraded to 1.6.7 and it was showing many of the libraries are invalid.
I thought this would be the reason for getting errors when run my programs. :o

I tried version 1.6.0 on your posted code and got this:

sketch_jan25a.ino: In function 'void setup()':
sketch_jan25a.ino:3:7: error: assigning to an array from an initializer list
Error compiling.

I don't see what libraries have got to do with it. You aren't using any.

I upgraded to 1.6.7 and it was showing many of the libraries are invalid.

Where exactly are the libraries installed ?

byte *getChar(int n, byte newChar[]) {
int i;
byte code[5] = {
B10000,
B11000,
B11100,
B11110,
B11111};

for (i = 0; i < 8; i++)
newChar = code[n - 1];

  • return newChar;*
    }

void setup() {

  • int i;*
  • float h;*
  • byte newChar[8];*

_ /* set up the LCD's number of rows and columns: */_

  • lcd.begin(16, 2);*

  • for (i = 1; i < 6; i++)*

  • lcd.createChar(i, getChar(i, newChar));*

  • newChar = {*

  • B00000,*

  • B00100,*

  • B01010,*

  • B01010,*

  • B11111,*

  • B00100,*

  • B00000,*

  • };*

  • lcd.createChar(ALARM_ICON, newChar);*

  • newChar = {*

  • B00011,*

  • B00101,*

  • B11001,*

  • B11001,*

  • B11001,*

  • B00101,*

  • B00011,*

  • };*

  • lcd.createChar(SOUND_ICON, newChar);*

  • newChar = {*

  • B00100,*

  • B10010,*

  • B01001,*

  • B01001,*

  • B01001,*

  • B10010,*

  • B00100,*

  • };*

  • lcd.createChar(SOUND_ICON_ON, newChar); *

  • pinMode(BUZZER_PIN, OUTPUT);*
    assigning to an array from an initializer list
    it shows this error

hashimashraf:
...
...
assigning to an array from an initializer list

it shows this error

Please edit your post and use code tags

** **[code]** **
your code here
** **[/code]** **
will result in

your code here

Did you read any of the previous replies that stated that what you are trying to do is not valid.

This part is valid because you initialise during a declaration.

  byte code[5] = {
    B10000,
    B11000,
    B11100,
    B11110,
    B11111};

This is not valid because it is a initialisation without a declaration

  newChar = {
    B00100,
    B10010,
    B01001,
    B01001,
    B01001,
    B10010,
    B00100,
  };

Change it to

newChar[0] = B00100;
newChar[1] = B10010;
...
...

Instead of trying to do it a way that can't be done why don't you try something like this instead!

#include <LiquidCrystal.h>

#define NUM_ENTRIES(ARRAY)  (sizeof(ARRAY) / sizeof(ARRAY[0]))

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

struct glyph_t
{
    uint8_t _bitmap[8];
};

glyph_t glyphs[] =
{
    {   // ALARM_ICON
          0b00000
        , 0b00100
        , 0b01010
        , 0b01010
        , 0b11111
        , 0b00100
        , 0b00000
        , 0b00000
    }
    ,
    {   // SOUND_ICON
          0b00011
        , 0b00101
        , 0b11001
        , 0b11001
        , 0b11001
        , 0b00101
        , 0b00011
        , 0b00000
    }
    ,
    {   // SOUND_ICON_ON
          0b00100
        , 0b10010
        , 0b01001
        , 0b01001
        , 0b01001
        , 0b10010
        , 0b00100
        , 0b00000
    }
};

void loop()
{   }
 
void setup()
{
    lcd.begin(16, 2);

    // set custom glyph bitmaps for every entry in the array 'glyphs'
    for ( size_t i = NUM_ENTRIES(glyphs); i--; )
    {
        lcd.createChar(i, glyphs[i]._bitmap);
    }
 
//    pinMode(BUZZER_PIN, OUTPUT);
}