Slowly making headway

I am using an Arduino Mega and connected to a Mac via USB. I do not have any shields on it. I finally got the Arduino connected to Cayenne and on my dashboard and can get a LED to light with the push of a button. So far so good. I had to run the cayenne-ser.sh script in the Terminal as instructed. So now I have the socat thing running in my Terminal.

Now when I try to add a slider with a dimming LED it asks that I install a new sketch into the Arduino. But it won’t upload the new sketch. I get an error message:

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

I then have to reload the original sketch, and get the same error messages, but then it manages to upload and I get back online with the Mega.

How do I add the slider with dimmer capability? How do I load a new sketch? I made sure the token was correct, and changed the CayenneEthernet.h to CayenneSerial.h and the pins were proper.

Should I use this sketch as my initial start up connect to the dashboard sketch, and then run the cayenne-ser.sh script? Am I missing something obvious? Also, I have found that once I have used a port for the initial connection, I can not load any more sketches using that port, even once I shut down the Terminal. I have to plug into a different USB port, until I have used them all up, then I have to reboot my entire computer. It says the port is in use and I have to stop whatever program is using it. But I have no idea how to determine which program is using it and how to shut it down. I tried with Activity Monitor and shut down the socat but that had no effect.

I am stoked that I even managed to get it connected, but want to be able to dim a LED or attach a servo. I can turn on and off the digital pins all day, and read an analog sensor, but no idea how to load the sketch that the dimming slider instructs me to load. Any help?

you are using the serial usb to get online with cayenne right? Do you have any other way to get online with it? I’ve never had good luck with the serial method.

AS far as the dimming, have you added the code to control it? Here is a example:

#define LED_VIRTUAL_PIN 1
#define LED_DIGITAL_PIN 3

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "AuthenticationToken";

void setup()
{
  Serial.begin(9600);
  Cayenne.begin(token);
}

CAYENNE_IN(LED_VIRTUAL_PIN)
{
  // get value sent from dashboard
  int currentValue = getValue.asInt(); // 0 to 1023
  analogWrite(LED_DIGITAL_PIN, currentValue / 4); // must be from 0 to 255
}

void loop()
{
  Cayenne.run();
}

Yes I am using a USB/serial connection.
I have that code, but adding it is what I am having an issue with. Do I add that sketch over the one I have now that allows me to even access the Board? Do I add it to the existing one?

This is what I have now:
*/

#include <CayenneSerial.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token = “xxxxxxxxxx”;

void setup()
{
//Baud rate can be specified by calling Cayenne.begin(token, 9600);
Cayenne.begin(token);
}

void loop()
{
Cayenne.run();
}

Because I have socat running in Terminal the serial port is busy. So…

Yeah, when adding on to your project you end up having to combine sketches, so you don’t lose your connection sketch for Cayenne, or any work you did for some other sensor. It can be a little tricky if you’re new and not a coder, but you’ll get a sense for it in time, and we’re happy to help.

Just looking at the base USBSerial connection sketch and what @vapor83 shared, here is how I’d combine them:

#include <CayenneSerial.h>
#define LED_VIRTUAL_PIN 1
#define LED_DIGITAL_PIN 3

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "AuthenticationToken";

void setup()
{
	//Baud rate can be specified by calling Cayenne.begin(token, 9600);
	Cayenne.begin(token);
}

void loop()
{
	Cayenne.run();
}

CAYENNE_IN(LED_VIRTUAL_PIN)
{
  // get value sent from dashboard
  int currentValue = getValue.asInt(); // 0 to 1023
  analogWrite(LED_DIGITAL_PIN, currentValue / 4); // must be from 0 to 255
}

I left out the Serial.begin(9600); line because I believe you’re right, the USB connection occupies the serial device, and it was only in his sketch for the purposes of printing messages.

Thank you!
Will try it as soon as I restart!

So that works, kinda. I can dim the LED and control it from the online dash, and it is stable, and I can see it on the phone. (iOS) but when I try to change it from the phone, I can, but then it jumps right to maximum and the number is off the scale, and show 326 or even higher, instead of staying with the scale of .1-1.0

What’s up with that?
Any help appreciated!

IS now stable when controlled from either dashboard. Learning this is challenging but cool!

I spoke too soon. Not so stable from the iOS device. Jumps to insane values. IS NOT STABLE.
Will jump from say .25 to 255.00 or .64 to 655.00 always same pattern, about 10,000 times greater than originally set.

Any help here? Is it the code? The widget? Am I doing something wrong?

Now I can’t even control the widget from the online computer dashboard! ARGH!

The ios slider seems to have issues for me too. The dashboard should work good though. What is it doing?

It is working properly now.
So here’s my next self-directed learning challenge. I have a motor shield on my Mega. I would like to learn how to control a DC motor using the Dashboard, both button on and off and a slider that will change the speed and direction of the motor.

It is frustrating because once I attach to a serial port, and have the script running that allows the connection, that port is closed to me, and I can’t upload any more sketches through that port, as it is busy. So I have to switch USB ports, and I only have three, then I need to reboot my entire system. There must be a way to flush the ports and make them available without that hassle, right?

I am totally new to programming, but am starting to get the hang of it thanks to some comprehensive and well tutorials. I still have a long way to go though!

Using the included examples as a starting point, (I have the example sketch for the motor shield loaded and do have a motor going back and forth. How do I modify that so that I can add a pot and use that to change speed and direction and then change the pot to a slider on the dashboard?

Thanks!

What OS and what version of the Arduino IDE are you using?

Arduino IDE 1.8.2 (I also have the older one if needed 1.0.5 ) and My OS X is Yosmite 10.10.5

incidentally, when I use the newest one, I get a bunch of errors.

Invalid library found in /Users/rob/Documents/Arduino/libraries/Blynk: /Users/rob/Documents/Arduino/libraries/Blynk
Invalid library found in /Users/rob/Documents/Arduino/libraries/Downloads: /Users/rob/Documents/Arduino/libraries/Downloads
Invalid library found in /Users/rob/Documents/Arduino/libraries/examples: /Users/rob/Documents/Arduino/libraries/examples
Invalid library found in /Users/rob/Documents/Arduino/libraries/IMU: /Users/rob/Documents/Arduino/libraries/IMU
Invalid library found in /Users/rob/Documents/Arduino/libraries/Joymos: /Users/rob/Documents/Arduino/libraries/Joymos
Invalid library found in /Users/rob/Documents/Arduino/libraries/JoymosSetup: /Users/rob/Documents/Arduino/libraries/JoymosSetup
Invalid library found in /Users/rob/Documents/Arduino/libraries/SabertoothArduinoLibraries: /Users/rob/Documents/Arduino/libraries/SabertoothArduinoLibraries
Invalid library found in /Users/rob/Documents/Arduino/libraries/sixdof: /Users/rob/Documents/Arduino/libraries/sixdof
Invalid library found in /Users/rob/Documents/Arduino/libraries/Blynk: /Users/rob/Documents/Arduino/libraries/Blynk
Invalid library found in /Users/rob/Documents/Arduino/libraries/Downloads: /Users/rob/Documents/Arduino/libraries/Downloads
Invalid library found in /Users/rob/Documents/Arduino/libraries/examples: /Users/rob/Documents/Arduino/libraries/examples
Invalid library found in /Users/rob/Documents/Arduino/libraries/IMU: /Users/rob/Documents/Arduino/libraries/IMU
Invalid library found in /Users/rob/Documents/Arduino/libraries/Joymos: /Users/rob/Documents/Arduino/libraries/Joymos
Invalid library found in /Users/rob/Documents/Arduino/libraries/JoymosSetup: /Users/rob/Documents/Arduino/libraries/JoymosSetup
Invalid library found in /Users/rob/Documents/Arduino/libraries/SabertoothArduinoLibraries: /Users/rob/Documents/Arduino/libraries/SabertoothArduinoLibraries
Invalid library found in /Users/rob/Documents/Arduino/libraries/sixdof: /Users/rob/Documents/Arduino/libraries/sixdof

Any idea how to fix that?
Thanks!

I can’t say that I’ve programmed an Arduino on a mac so maybe someone else can help out there, but since you have the new version of Arduino your USB problems shouldn’t be an IDE/driver issue. As far as the library errors you may have to update them or just manually delete them.

Hi Robert,

I have a Mac and is it with the Cayenne USB Serial connection a decent amount. Mine is running 10.12.4 Sierra but I don’t think that matters here. You shouldn’t have to jump between ports like that. It is true that the port is busy while you have a USB Serial Connection established, but if you stop the cayenne-ser.sh sketch with Control-C, then the port should be available again in the Arduino IDE. No need to even disconnect the Arduino. Then after you’ve uploaded your new sketch, just restart the cayenne-ser.sh script with sudo ./cayenne-ser.sh

As for the ‘Invalid Library’ errors, I’ve not seen those before, but with some Googling they seem to be related to an invalid folder structure from what the Arduino IDE wants in each of these cases. This thread seems to explain it pretty well: Invalid library found - Installation & Troubleshooting - Arduino Forum

It seems like it could also happen from storing your sketch files in any subfolder of /Users/rob/Documents/Arduino/libraries/ so I’d avoid that if you were doing it:

If you’re not able to correct it, it may be worth just deleting those libraries and searching for / re-adding them through the Library Manager in the Arduino IDE. Just make sure that if you were storing your personal sketch data in there that you back it up before deleting whole folders!

I’m happy to help troubleshoot it if you want to try to unravel each of them, but I’d probably need to see the whole folder tree (maybe a screenshot from finder with things expanded?) to see what may have gone wrong.