Author Topic: Software Serial bug on MoteinoMEGA? [FIXED]  (Read 8313 times)

dave_sausages

  • NewMember
  • *
  • Posts: 49
Software Serial bug on MoteinoMEGA? [FIXED]
« on: August 22, 2016, 01:20:27 PM »
To cut a long story short, I have a Moteino Mega that I need to have a GPS receiver and hm-10 bluetooth radio attached to (amongst other things).

Serial0 is used for serial monitor (and eventually another serial comms link anyway)

Serial1 is successfully being used for gps.

I've run out of serial ports so I've been trying to use Software Serial for the bluetooth radio.....but it just won't work. I've used a spare Arduino Pro mini 3.3v to test software serial on linked to the bluetooth radio, and all is well. So I can confirm it is the Moteino Mega not working with Software serial.

Tx ic connected to pin 14, Rx to pin 13.

I've seen in various threads on here that other have had the same problems, but there's never a definitive answer or solution?

Can anyone help?

P.S. the software serial connection also works on my standard Moteino. 
« Last Edit: August 24, 2016, 08:16:44 PM by Felix »

luisr320

  • Sr. Member
  • ****
  • Posts: 255
  • Country: pt
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #1 on: August 22, 2016, 05:30:52 PM »
Can you post the non working code that you are trying to use on the Mega?

dave_sausages

  • NewMember
  • *
  • Posts: 49
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #2 on: August 22, 2016, 05:35:15 PM »
Here it is:

Code: [Select]
#include <SoftwareSerial.h>


int bluetoothTx = 14;  /* TX-O pin of bluetooth*/
int bluetoothRx = 13;  /* RX-I pin of bluetooth */

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
 

  Serial.begin(9600);  // Begin the serial monitor at 9600bps


  delay(100);  // Short delay, wait for the Mate to send back CMD
  bluetooth.begin(9600);  // Start bluetooth serial at 9600
  Serial.print("init");
  bluetooth.println("AT+RENEW");

}

void loop()
{
  if(bluetooth.available())  // If the bluetooth sent any characters
  {
    // Send any characters the bluetooth prints to the serial monitor
    Serial.print((char)bluetooth.read()); 
  }
  if(Serial.available())  // If stuff was typed in the serial monitor
  {
    // Send any characters the Serial monitor prints to the bluetooth
    bluetooth.print((char)Serial.read());
  }
  // and loop forever and ever!
}
« Last Edit: August 24, 2016, 08:22:08 PM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #3 on: August 22, 2016, 07:01:02 PM »
Should work, did you try other pins?
I can't remember if I ever tried software serial on the 1284p, maybe not because I never had a need since there's the extra hardware serial.
It's possible there's a limitation in the softwareserial library that causes it to not work on 1284p.

UPDATE:The issues and solution are explained in this post.
« Last Edit: August 24, 2016, 08:17:58 PM by Felix »

dave_sausages

  • NewMember
  • *
  • Posts: 49
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #4 on: August 22, 2016, 08:57:28 PM »
I have now tried pins 13 and 14, 22 and 23, 0 and 1, and 20 and 21. And I always get no response on the serial monitor when I type "AT". "init" shows up as always.

There must be a way to get sortware serial working. It seems daft that the standard Moteino can do something that the Mega can't.

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #5 on: August 22, 2016, 09:34:27 PM »
Don't forget the 1284p has JTAG, this should be disabled in the fuses if you want to use those 4 pins.
Mark.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #6 on: August 22, 2016, 10:13:07 PM »
See this arduino thread. The problems sound identical to yours.
My MEGA core was initially based on the mighty1284 core. I have looked at this briefly but I didn't have time to try the code they share (see p2).
See if it's something you can do/try and if it gets you any closer to a solution, let us know your progress or any updates...

Also FWIW I just found yet another older thread reporting the same issue. It starts to sound like an issue with the SS library/pin map being incompatible with the 1284p.
« Last Edit: August 22, 2016, 10:21:02 PM by Felix »

dave_sausages

  • NewMember
  • *
  • Posts: 49
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #7 on: August 23, 2016, 12:43:35 AM »
I'm not too sure what I'm doing, but I have the hardware all here fully set up and ready to go, and 2 days free. So if anyone can help steer me in the right direction (even just by saying you need to replace the code in file_x with this code.....and make sure you do/don't do this________).

I'll have a go myself, but I hope I won't break anything.

Any pointers Felix? Doesn't need to be too specific, just a shove in the right direction and a bit more of a hint and I'll google away.

dave_sausages

  • NewMember
  • *
  • Posts: 49
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #8 on: August 23, 2016, 12:44:49 AM »
Don't forget the 1284p has JTAG, this should be disabled in the fuses if you want to use those 4 pins.
Mark.
Which 4 pins? Why would I need to use JTAG?

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #9 on: August 23, 2016, 05:39:02 AM »
JTAG is enabled by default in the fuses, this means the TCK,TMS,TDO and TDI pins (pins 21 to 24 inclusive on the TQFP) cannot be used for user I/O, they're pre-allocated to JTAG so that the device can be programmed by JTAG. You can turn JTAG off in the fuse settings, this liberates those pins for user IO. It's a classic thing to look for when using devices with JTAG.

Mark.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #10 on: August 23, 2016, 10:15:25 AM »
Actually JTAG is disabled on the MoteinoMEGAs.
See the thread I posted, there is some code shared there that might be useful.

dave_sausages

  • NewMember
  • *
  • Posts: 49
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #11 on: August 23, 2016, 02:35:54 PM »
So I've got software serial working.......well sort of.

I installed the Mighty 1284p core files from  JChristensen from here https://github.com/JChristensen/mighty-1284p/tree/v1.6.3

And then selected "maniacbug" Mighty 1284p 16MHz using Optiboot as the board type in Arduino IDE.

Clicked upoad sketch and I now have software serial talking to my bluetooth radios!!!  :)

My "sort of" caveat is that obviously I am now uploading to my Moteino Mega board, but telling my Arduino IDE that it's a different board.

What are the differences, and will it cause me any problems?

Note: My solution came from here https://forum.arduino.cc/index.php?topic=358528.0 /dev's suggestions on changing pin mappings seemed a little over my head.

Thanks

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #12 on: August 23, 2016, 03:13:23 PM »
Thanks for the update!
I'll need to look into this and how that core is different. Pin mappings should not really matter that much because they just handle what core pin corresponds to what pin number on the board.
But anyway I hope to get some time to debug it and see where the problem is and if I can correct it.

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #13 on: August 23, 2016, 05:01:02 PM »
Actually JTAG is disabled on the MoteinoMEGAs.
See the thread I posted, there is some code shared there that might be useful.
Ah, OK. Presumably you program them before shipping, I believe the factory shipped state is to have JTAG enabled as that may be your primary programming source. I've been caught out a couple of times with JTAG being enabled.
Mark.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #14 on: August 23, 2016, 10:22:56 PM »
@perky - I set the fuses and bootloader after assembly. Fuses shown in the diagram (subject to change):