chipKIT® Development Platform

Inspired by Arduino™

Chipkit lenny can't get software serial to work

Created Tue, 14 Nov 2017 22:38:12 +0000 by sternfox


sternfox

Tue, 14 Nov 2017 22:38:12 +0000

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()) 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) else if (digitalRead(button2) == 0) stepper.setSpeed(sign * spd); stepper.runSpeed(); }


majenko

Tue, 14 Nov 2017 22:58:59 +0000

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...


EmbeddedMan

Wed, 15 Nov 2017 02:49:51 +0000

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

Wed, 15 Nov 2017 10:44:36 +0000

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


majenko

Wed, 15 Nov 2017 13:45:06 +0000

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

Serial0.begin(115200);

sternfox

Wed, 15 Nov 2017 17:06:03 +0000

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.

#include &lt;AccelStepper.h&gt; // 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();
}

majenko

Wed, 15 Nov 2017 18:39:58 +0000

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