Can't get this to compile on the Grand Central M4

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Gary_J
 
Posts: 7
Joined: Mon Nov 08, 2021 5:10 pm

Can't get this to compile on the Grand Central M4

Post by Gary_J »

Hi!
I have been doing sketches for some time on my Mega 2560 and have moved over (trying..) to the Grand Central and have a compile issue and can't find an example of how this should be re-written.

This modified Blink sketch does compile for the Mega and does not for the Grand Central...
The parts I have added are pieces of a larger sketch that (this part) write over to another board using i2c, an output state for a tension control, where one motor is set to turn clockwise and the other, counter clockwise (and vice-versa).

Code: Select all

#include <Wire.h>

unsigned int duration;
/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  LoosenTension();
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  TightenTension();
  delay(1000);                       // wait for a second
}
//======================================================================================================
void LoosenTension() {
  setDurTension(9, (unsigned int)100); // infeed direction 1100 is normal 100 is backwards = to loosen
  setDurTension(10, (unsigned int)1100); // exit direction 100 is normal 1100 is backwards = to loosen
}

void TightenTension() {
  setDurTension(9, (unsigned int)1100); // infeed direction 1100 is normal 100 is backwards = to loosen
  setDurTension(10, (unsigned int)100); // exit direction 100 is normal 1100 is backwards = to loosen
}

void setDurTension(uint8_t DAC, unsigned int duration) { //Tension Bool to make a pin low or high to enable or disable tension 9 and 10 are direction 11 and 12 are frequency
  Wire.beginTransmission(10);
  Wire.write(DAC);

  const unsigned char val1 = duration & 0xFF;
  const unsigned char val2 = (duration >> 8) & 0xFF;

  Wire.write(val1);
  Wire.write(val2);
  Wire.endTransmission();
}
'setDurTension' was not declared in this scope


Any thoughts are appreciated!
Thanks, Gary

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Can't get this to compile on the Grand Central M4

Post by dastels »

Try moving the definition of setDurTension to a spot before it is referenced. Do the same for LoosenTension and TightenTension.

Dave

User avatar
Gary_J
 
Posts: 7
Joined: Mon Nov 08, 2021 5:10 pm

Re: Can't get this to compile on the Grand Central M4

Post by Gary_J »

Thanks, for the reply.
I am not sure I follow.. if move it up, it does give me a different error " expected primary-expression before 'unsigned' "
but I believe this error stems from the way the void is set up: void setDurTension(uint8_t DAC, unsigned int duration). The examples I see on forums and such don't seem to use this method. Is there another way of structuring this so it can be "simpler"...like:
void setDurTension( ) {

setDurTension(uint8_t DAC, unsigned int duration)

}

I realize this bit above is not going to work and in fact gave me the same error " expected primary-expression before 'unsigned' "
.. I have to laugh.. I am just not seeing it

:)
Gary

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Can't get this to compile on the Grand Central M4

Post by dastels »

I was on the wrong path. Go back to your original; code as posted. DAC in the setDurTension function ... change it to all lower case. DAC appears to be a macro defined in one of the GrandCentral headers. The result is that it's getting textually replaced. Just one of the joys of the C/C++ preprocessor.

It compiles for me with the GrandCentral selected as the board.

Dave

User avatar
Gary_J
 
Posts: 7
Joined: Mon Nov 08, 2021 5:10 pm

Re: Can't get this to compile on the Grand Central M4

Post by Gary_J »

Hi Dave,
Amazing! I would have never guessed that... It compiles for me also.
Thanks for your help. Back earlier in this code's use, it was using a frequency as an input for a D.A.C. for a machine control and when we needed a frequency for a stepper, the code was repurposed and carried the DAC part in at that point.
I had been plugging away here and managed to inadvertently move past the bug with this rendering where DAC was removed (I didn't know it was the issue):

Code: Select all

#include <Wire.h>

unsigned int duration = 0;
unsigned char val1 = 0;
unsigned char val2 = 0;

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  LoosenTension();
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  TightenTension();
  delay(1000);                       // wait for a second
}
//======================================================================================================

void LoosenTension() {
  // infeed direction 1100 is normal 100 is backwards = to loosen
  duration = 100;
  Write9toDevice10();

  // exit direction 100 is normal 1100 is backwards = to loosen
  duration = 1100;
  Write10toDevice10();
}

void TightenTension() {
  // infeed direction 1100 is normal 100 is backwards = to loosen
  duration = 1100;
  Write9toDevice10();

  // exit direction 100 is normal 1100 is backwards = to loosen
  duration = 100;
  Write10toDevice10();

}

void Write9toDevice10() {
  Wire.beginTransmission(10);
  Wire.write(9);

  val1 = duration & 0xFF;
  val2 = (duration >> 8) & 0xFF;

  Wire.write(val1);
  Wire.write(val2);
  Wire.endTransmission();
}

void Write10toDevice10() {
  Wire.beginTransmission(10);
  Wire.write(10);

  val1 = duration & 0xFF;
  val2 = (duration >> 8) & 0xFF;

  Wire.write(val1);
  Wire.write(val2);
  Wire.endTransmission();
}
Thanks again!
Gary

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”