-5

How do I ever understand what the Arduino IDE means when they advise you of any errors? The reason I ask is because I got several errors that don't make sense to me as I see what the error means and what line the issue is but I don't see anything wrong with the code. It's written how it should be, the reason I say this is because before I ended the code I was compiling/verifying my code every time I write a new line just to make sure if I got new errors. It's easy to check as it was more than likely the very last line of code I just wrote, rather than write a book then do a spell check you know?

I have included the part of the code where I get errors and the errors themselves. Hopefully someone can point out to me what is it that Arduino sees that I don't and in the same token I'll learn how to counter measure those errors.

1.  //imu's
2.  #include "Wire.h" // i dont think this will be needed on this mcu's "slaves"
3.  #include "I2Cdev.h" // i dont think this will be needed on this mcu's "slaves"
4.  #include "MPU6050.h" // i dont think this will be needed on this mcu's "slaves"
5.  
6.  //motors
7.  #include "Servo.h" // select which motor this slave mcu has and comment out the other
8.  #include "Stepper.h" // select which motor this slave mcu has and comment out the other
9.  
10. //wireless
11. #include "nRF24L01.h"
12. #include "RF24.h"
13. #include "SPI.h" // i dont think this will be needed on this mcu's "slaves"
14. 
15. #define RF_CS 12
16. #define RF_CSN 13
17. RF24 radio(RF_CS, RF_CSN);//RF24 radio(9, 10);
18. const int pinCE = 9;
19. const int pinCSN = 10;
20. 
21. byte bArray[] = {0000, 1000, 0100, 1100, 0010, 1010, 0110, 1110}; // this are the Ch 0/7 address from Mux
22. const uint64_t LA = 0xF0F0F0F0D2LL;//mcu1 address of Slave
23. const uint64_t RA = 0xF0F0F0F0C3LL;//mcu2 address of Slave
24. const uint64_t LL = 0xF0F0F0F0B4LL;//mcu3 address of Slave
25. const uint64_t RL = 0xF0F0F0F0A5LL;//mcu4 address of Slave
26. const uint64_t LW = 0xF0F0F0F0E6LL;//mcu5 address of Slave
27. const uint64_t RW = 0xF0F0F0F0F7LL;//mcu6 address of Slave
28. const uint64_t UT = 0xF0F0F0F0F8LL;//mcu7 address of Slave
29. const uint64_t BT = 0xF0F0F0F0F9LL;//mcu8 address of Slave
30. 
31. /* MUX CH address To simplify things, 1 is HIGH, 0 is LOW
32.                                                                     0000 – 0
33.                                                                     1000 – 1
34.                   A multiplexer of this sort really just            0100 – 2
35.                   acts as a 16 to one 1 switch. The 4 digital       1100 – 3
36.                   pins are used to set HIGH or LOW, in a binary     0010 – 4
37.                   fashion (0-15) to determine what pin “SIG” is      1010 – 5
38.                   connected to. So bringing all 4 pins LOW would    0110 – 6
39.                   switch the CD74HC4067 to channel 0 (so SIG and    1110 – 7
40.                   C0 would be connected), bringing them all HIGH    0001 – 8
41.                   would switch it to 15 (so SIG and C15 would be    1001 – 9
42.                   connected)                                        0101 – 10
43.                                                                     1101 – 11
44.                                                                     0011 – 12
45.                                                                     1011 – 13
46.                                                                     0111 – 14
47.                                                                     1111 – 15 */
48. 
49. int recivers[8][4] = {
50.   { 0xF0F0F0F0D2LL, { 0, 0, 0, 0 }, //0000 – 0 SDATA line from MPU to Multiplexer ch0
51.     { 0xF0F0F0F0C3LL, { 1, 0, 0, 0 }, //1000 – 1 SDATA line from MPU to Multiplexer ch1
52.       { 0xF0F0F0F0B4LL, { 0, 1, 0, 0,}, //0100 – 2 SDATA line from MPU to Multiplexer ch2
53.         { 0xF0F0F0F0A5LL, { 1, 1, 0, 0 }, //1100 – 3 SDATA line from MPU to Multiplexer ch3
54.           { 0xF0F0F0F0D6LL, { 0, 0, 1, 0 }, //0010 – 4 SDATA line from MPU to Multiplexer ch4
55.             { 0xF0F0F0F0E7LL, { 1, 0, 1, 0 }, //1010 – 5 SDATA line from MPU to Multiplexer ch5
56.               { 0xF0F0F0F0F8LL, { 0, 1, 1, 0 }, //0110 – 6 SDATA line from MPU to Multiplexer ch6
57.                 { 0xF0F0F0F0F9LL, { , 1, 1, 1, 0 } //1110 – 7 SDATA line from MPU to Multiplexer ch7
58.                 }
59.               }
60.             }
61.           }
62.         }
63.       }
64.     }
65.   }
66. }
67. 
68. MPU6050 mpu;
69. int16_t ax, ay, az;
70. int16_t gx, gy, gz;
71. 
72. long long  val[6];//6 DOF MPU 6050 thats where this val{6} come from
73. long val;
74. long prevVal;
75. 
76. byte bArray[] = ( 0, 180 );
77. 
78. //Mux control pins on the Arduino Digital pins
79. int s0 = 8;
80. int s1 = 7;
81. int s2 = 6;
82. int s3 = 5;
83. 
84. //Mux in "SIG" pin
85. int SIG_pin = 0;
86. //int val = readMux(7);
87. 
88. void setup()
89. {
90.   pinMode(s0, OUTPUT);
91.   pinMode(s1, OUTPUT);
92.   pinMode(s2, OUTPUT);
93.   pinMode(s3, OUTPUT);
94. 
95.   digitalWrite(s0, LOW);
96.   digitalWrite(s1, LOW);
97.   digitalWrite(s2, LOW);
98.   digitalWrite(s3, LOW);
99. 
100.      Wire.begin();
101.    
102.      for (int i = 0; i < 10; i++) //10 mpu's
103.      {
104.        mpu.initialize();
105.      }
106.    
107.      radio.begin();
108.      radio.payload = 6;
109.      radio.setAutoAck(false);
110.      radio.setDataRate(RF24_2MBPS);
111.      radio.openWritingPipe();
112.    }
113.    
114.    void loop()
115.    {
116.      for (int i = 0; i < 16; i ++)//Loop through and read all 16 values
117.      {
118.        int readMux(int channel)
119.    
120.        int controlPin[] = {s0, s1, s2, s3};
121.    
122.        int muxChannel[8][4] = {
123.          {0, 0, 0, 0}, //channel 0
124.          {1, 0, 0, 0}, //channel 1
125.          {0, 1, 0, 0}, //channel 2
126.          {1, 1, 0, 0}, //channel 3
127.          {0, 0, 1, 0}, //channel 4
128.          {1, 0, 1, 0}, //channel 5
129.          {0, 1, 1, 0}, //channel 6
130.          {1, 1, 1, 0}, //channel 7
131.          {0, 0, 0, 1}, //channel 8
132.          {1, 0, 0, 1}, //channel 9
133.          //  {0, 1, 0, 1}, //channel 10
134.          //  {1, 1, 0, 1}, //channel 11
135.          //  {0, 0, 1, 1}, //channel 12
136.          //  {1, 0, 1, 1}, //channel 13
137.          //  {0, 1, 1, 1}, //channel 14
138.          //  {1, 1, 1, 1}  //channel 15
139.        }
140.      }
141.      //loop through the 4 sig
142.      for (int i = 0; i < 4; i ++)
143.      {
144.        digitalWrite(controlPin[i], muxChannel[channel][i]);
145.      }
146.    
147.      //read the value at the SIG pin
148.      int val = analogRead(SIG_pin);
149.    
150.      //return the value
151.      return val;
152.    
153.      for (int i = 0; i < 6 i++)
154.      {
155.        mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
156.        val[0] = map(ax, -17000, 17000, 0, 180);
157.        val[1] = map(ay, -17000, 17000, 0, 180);
158.        val[2] = map(az, -17000, 17000, 0, 180);
159.        val[3] = map(gz, -17000, 17000, 0, 180);
160.        val[4] = map(gy, -17000, 17000, 0, 180);
161.        val[5] = map(gx, -17000, 17000, 0, 180);
162.    
163.        radio.openWritingPipe(recievers[i].address);
164.        radio.write(val);
165.      }
166.    
167.      delay(50);


    Arduino: 1.6.4 (Windows 8.1), Board: "Arduino Nano, ATmega328"

    sketch_may19a:57: error: expected primary-expression before ',' token
    sketch_may19a:66: error: braces around scalar initializer for type 'int'
    sketch_may19a:68: error: expected ',' or ';' before 'MPU6050'
    sketch_may19a:73: error: conflicting declaration 'long int val'
    sketch_may19a:72: error: 'val' has a previous declaration as 'long long int                val [6]'
    sketch_may19a:76: error: redefinition of 'byte bArray []'
    sketch_may19a:21: error: 'byte bArray [8]' previously defined here
    sketch_may19a.ino: In function 'void setup()':
    sketch_may19a:104: error: 'mpu' was not declared in this scope
    sketch_may19a:108: error: 'class RF24' has no member named 'payload'
    sketch_may19a:111: error: no matching function for call to         'RF24::openWritingPipe()'
    sketch_may19a.ino:111:25: note: candidate is:
    In file included from sketch_may19a.ino:12:0:
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:324:8: note: void     RF24::openWritingPipe(uint64_t)
    void openWritingPipe(uint64_t address);
    ^
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:324:8: note:   candidate         expects 1 argument, 0 provided
    sketch_may19a.ino: In function 'void loop()':
    sketch_may19a:120: error: expected initializer before 'int'
    sketch_may19a:139: error: too many initializers for 'int [8][4]'
    sketch_may19a:140: error: expected ',' or ';' before '}' token
    sketch_may19a:144: error: 'controlPin' was not declared in this scope
    sketch_may19a:144: error: 'muxChannel' was not declared in this scope
    sketch_may19a:144: error: 'channel' was not declared in this scope
    sketch_may19a:151: error: return-statement with a value, in function     returning     'void' [-fpermissive]
    sketch_may19a:153: error: expected ';' before 'i'
    sketch_may19a:155: error: 'mpu' was not declared in this scope
    sketch_may19a:156: error: invalid types 'int[int]' for array subscript
    sketch_may19a:157: error: invalid types 'int[int]' for array subscript
    sketch_may19a:158: error: invalid types 'int[int]' for array subscript
    sketch_may19a:159: error: invalid types 'int[int]' for array subscript
    sketch_may19a:160: error: invalid types 'int[int]' for array subscript
    sketch_may19a:161: error: invalid types 'int[int]' for array subscript
    sketch_may19a:163: error: 'recievers' was not declared in this scope
    sketch_may19a:164: error: no matching function for call to 'RF24::write(int&)'
    sketch_may19a.ino:164:20: note: candidate is:
    In file included from sketch_may19a.ino:12:0:
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:281:8: note: bool     RF24::write(const void*, uint8_t)
   bool write( const void* buf, uint8_t len );
    ^
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:281:8: note:candidate     expects 2 arguments, 1 provided
    expected primary-expression before ',' token
  • 4
    Please post the entire code (with the #include lines at the top). – Gerben May 5 '15 at 19:35
  • Can you add line numbers to the code? As without them it is hard to determine which lines the errors refer to. Can you indent the code to make it more readable? Where are mpu and radio declared? – Greenonline May 6 '15 at 0:39
  • Also, as Spiked3 points out in his answer, the remapped values (of ax, az, gz, gy and gx) assigned to val are discarded, as you successively reassign val with new mapped values, without using the previous value. So only the remapped value of ay is tested. Is this intentional? Should the (val != prevVal) test not be repeated after each remapping? – Greenonline May 7 '15 at 6:13
  • Regardless, as you are a new user, welcome to SE Arduino, Frank..! :-) Please consider reading the tour page. – Greenonline May 7 '15 at 10:34
  • 1
    Replacing your original question with gibberish, once people have taken considerable trouble to answer it, is irritating. It is disrespectful of the effort they have put into their answers. -1 vote for doing this. – Nick Gammon Aug 7 '15 at 7:34
3

You do know that you assign 6 different values to val, before you use the last one?

And assigning 4 interrupts? I have to question how well you understand what you are doing.

Google pastebin for a method of posting all of your code before asking for help. And be sure to include what you have already tried and how it failed. People are much more likely to help, as opposed to do it for you.

update: As pointed out using pastebin is not a good long term solution, just a quick fix.

You are doing quite a few newb things in your code. There is nothing wrong with that we were all newbs at some point.

First, you are driving 21 servos? Assuming you board has 21 PWM pins, do you realize they could be drawing up a half amp or more each? If at 1/2 that it would still be around 5 amps, that is probably 100 times more than the Arduino can handle. So I hope you have made provisions to power them externally.

The first real error is on line 130. You define a stepper motor called GzUT, then you pass it to a function expecting a pin number. This is not correct, and I also suspect the 'stepper' library would already set up the pins and there is no need for you to do that. Even beyond that, you declare the GzUT as part of a structure, but you never create a variable that is made of that structure.

This is indicative you are not an experienced programmer, and an embedded program is not the place to learn how to program.

You are trying to do too much at first. Go slower. Get 1 servo (or stepper) to work. then add the others once you understand how to do that. Refer to samples from the stepper library web site. (http://www.arduino.cc/en/Tutorial/MotorKnob)

The MPU-6050 is also a somewhat more advanced sensor. It look like you plan on multiplexing them? With an I2C multiplexer? Have you thought out the addressing? Do you have any idea of timing requirements of 21 servos and multiple i2c data streams and if the processor is even capable of meeting those requirements? My experience with an Arduino UNO is it barely can keep up with 1 mpu-6050. I doubt if you can add more than one servo.

The Arduinos in general are awesome prototype platforms. They are great for learning embedded programming. But they are not so good for just learning to program in general, especially when you are trying to do a lot of work, of which 21 servos certainly qualifies as. Again, my recommendation would be slow down, do one small thing at a time, or if this is a real project, contract it out to someone with experience.

Update: I didn't mean to offend. It is just unclear from your question and your code how much experience you have or do not have. That being said, I am not able to figure out which of the rlf2401 libraries you are trying to use. There 5 of them mentioned on this Arduino page http://playground.arduino.cc/InterfacingWithHardware/Nrf24L01. So follow up with which one you used and I will take a look.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.