Chipkit lenny can't get software serial to work

Post Reply
sternfox
Posts: 3
Joined: Tue Nov 14, 2017 11:25 pm

Chipkit lenny can't get software serial to work

Post by sternfox » Tue Nov 14, 2017 11:38 pm

Hi there. I have just purchased a lenny board. I also have a uno and wanted to use the uno sketch on my lenny but can't get the blutooth to connect. Here is the sketch. Any help would be appreciated. It works on my uno.



#include <AccelStepper.h> // Library created by Mike McCauley at http://www.airspayce.com/mikem/arduino/AccelStepper/
// AccelStepper Setup
AccelStepper stepper(1, 5, 6); // 1 = Easy Driver interface, Pin 4 connected to STEP pin of Easy Driver, Pin 5 connected to DIR pin of Easy Driver

#include <SoftwareSerial.h>
SoftwareSerial portOne(0, 1); // software serial #1: TX = digital pin 10, RX = digital pin 11


// Define our three input button pins
#define button1 3
#define button2 2

int spd = 8000; // The current speed in steps/second
int sign = 0; // Either 1, 0 or -1

void setup()
{
Serial.begin(9600);
stepper.setMaxSpeed(10000);
stepper.setSpeed(1000);

// Set up the three button inputs, with pullups
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
}

void loop()
{
char c;
if(Serial.available()) {
c = Serial.read();
if (c == 'f') { // forward
sign = 1;
}
if (c == 'r') { // reverse
sign = -1;
}
if (c == 's') { // stop
sign = 0;
}
if (c == '1') { // super slow
spd = 10;
}
if (c == '2') { // slow
spd = 100;
}
if (c == '3') { // medium
spd = 300;
}
if (c == '4') { // fast
spd = 500;
}
if (c == '5') { // faster
spd = 8000;
}
if (c == '6') { // superfast
spd = 10000;
}
}
if (digitalRead(button1) == 0) {
sign = 1;
}
else if (digitalRead(button2) == 0) {
sign = -1;
}
stepper.setSpeed(sign * spd);
stepper.runSpeed();
}

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Chipkit lenny can't get software serial to work

Post by majenko » Tue Nov 14, 2017 11:58 pm

I'm not sure SoftwareSerial actually works at all. I've never had call to use it.

But then, why would you? Pins 0/1 (and pins 2/4) are hardware UARTs anyway...
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Chipkit lenny can't get software serial to work

Post by EmbeddedMan » Wed Nov 15, 2017 3:49 am

sternfox: Majenko's quite right - it is much better to use the many hardware UARTS on chipKIT boards first, and only resort to software serial if you absolutely need to.

That said, I have done some extensive testing of the software serial library on chipKIT, and it does work pretty well (as long as you don't try to go too fast). So if you absolutely need it to work, let me know, and I'll help you debug it.

But hardware is a much better bet for you-

*Brian

sternfox
Posts: 3
Joined: Tue Nov 14, 2017 11:25 pm

Re: Chipkit lenny can't get software serial to work

Post by sternfox » Wed Nov 15, 2017 11:44 am

Many thanks for the swift replies, Please forgive me as I am new to this. So I don't have to use software serial lib with the lenny how would I define the pins and baud rate in my sketch without softwearserial?

Many thanks.

Chris

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Chipkit lenny can't get software serial to work

Post by majenko » Wed Nov 15, 2017 2:45 pm

You don't define the pins - in exactly the same way that you don't define the pins on an Arduino.

Code: Select all

Serial0.begin(115200);
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

sternfox
Posts: 3
Joined: Tue Nov 14, 2017 11:25 pm

Re: Chipkit lenny can't get software serial to work

Post by sternfox » Wed Nov 15, 2017 6:06 pm

Still having trouble getting it to work, I have the TX connected to RX0 and RX to TX and have tried pins 2 and 4 but still no communication.

this is the code i have tried. The code i posted in the first post works with the UNO no problems just wont work with this board.

Code: Select all

#include <AccelStepper.h> // Library created by Mike McCauley at http://www.airspayce.com/mikem/arduino/AccelStepper/
// AccelStepper Setup
AccelStepper stepper(1, 5, 6);  // 1 = Easy Driver interface, Pin 4 connected to STEP pin of Easy Driver, Pin 5 connected to DIR pin of Easy Driver

// Define our three input button pins
#define  button1 3
#define  button2 2

int spd = 8000;    // The current speed in steps/second
int sign = 0;      // Either 1, 0 or -1
 
void setup()
{ 
  Serial1.begin(9600);
  stepper.setMaxSpeed(10000);
  stepper.setSpeed(1000);
  
  // Set up the three button inputs, with pullups
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
}

void loop()
{ 
  char c;
  if(Serial1.available()) {
    c = Serial1.read();
    if (c == 'f') {  // forward
      sign = 1;
    }
    if (c == 'r') {  // reverse
      sign = -1;
    }
    if (c == 's') {  // stop
      sign = 0;
    }
    if (c == '1') {  // super slow
      spd = 10;
    }
    if (c == '2') {  // slow
      spd = 100;
    }
    if (c == '3') {  // medium
      spd = 300;
    }
       if (c == '4') {  // fast
      spd = 500;
    }  
       if (c == '5') {  // faster
      spd = 8000;
    }  
       if (c == '6') {  // superfast
      spd = 10000;
    }
  }
  if (digitalRead(button1) == 0) {
    sign = 1;
  }
  else if (digitalRead(button2) == 0) {   
    sign = -1;
  }
  stepper.setSpeed(sign * spd);
  stepper.runSpeed();
}

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Chipkit lenny can't get software serial to work

Post by majenko » Wed Nov 15, 2017 7:39 pm

Serial1 is pins 2 and 4. For pins 0 and 1 it's Serial0 - like I showed above.
  • Serial: USB port
  • Serial0: Pins 0/1 UART
  • Serial1: Pins 2/4 UART
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

Post Reply