Author Topic: Software Serial bug on MoteinoMEGA? [FIXED]  (Read 8312 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):


Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Can Software Serial work on a Moteino Mega? And if so, how?
« Reply #15 on: August 24, 2016, 08:15:56 PM »
OK I found the problem!
There are 2 issues:

Issue #1 - the MoteinoMEGA core
There were some incorrect PCMSK definitions in the pins_arduino.h file. This is now corrected and all core ZIP files are updated including the one for the BoardManager.
If you want to do a manual install follow the instructions in the repo here.
Otherwise if you want to update/install (v 1.2 as of now) through the BoardManager, see the guide here.

Issue #2 - your sketch
Your original sketch has an error, the pin definitions are passed in the wrong order to the SoftwareSerial constructor, please see the SoftwareSerial constructor reference here, the correct constructor is this:

Code: [Select]
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx); <------ Original from your sketch: INCORRECT PIN ORDER
SoftwareSerial bluetooth(bluetoothRx, bluetoothTx); <------ Use this instead

Thanks for bringing this up to my attention, please test the new core ZIP and let me know if everything is good.
-Felix
« Last Edit: August 24, 2016, 08:21:30 PM by Felix »

dave_sausages

  • NewMember
  • *
  • Posts: 49
Re: Software Serial bug on MoteinoMEGA? [FIXED]
« Reply #16 on: September 07, 2016, 11:46:49 AM »
I can confirm that software serial now works when selecting Moteino Mega in the IDE and uploading the sketch (using updated core files). Thanks Felix, and glad to be of some help to others for once, rather than just asking questions :)

simon pearce

  • NewMember
  • *
  • Posts: 2
  • Country: nz
Re: Software Serial bug on MoteinoMEGA? [FIXED]
« Reply #17 on: November 03, 2016, 03:41:16 AM »
Hi all,

Just a quick one, I've updated cores etc and tried to follow the thread here for the fix but am still not getting Software Serial operational. I am using a Moteino Mega with software serial using pins 17,18, I can get comms in one direction only. I am using arduino ide 1.6. Is there anything else I could try? I know this is down as being fixed and possibly I am misunderstanding but I'm getting tough going here, any help would be greatly appreciated!

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Software Serial bug on MoteinoMEGA? [FIXED]
« Reply #18 on: November 03, 2016, 08:15:42 AM »
@simon,
What exactly is the behavior?
Does the baud match on both ends and that TX/RX are properly wired?
Are you sure you got the latest Moteino core installed which has the soft serial fix included? This was verified to work by myself and others here.
Can you verify other pair(s) pins?

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Software Serial bug on MoteinoMEGA? [FIXED]
« Reply #19 on: November 03, 2016, 08:40:02 AM »
If the Moteino Mega uses the atmega1284P then pin 18 is possibly on JTAG TCK, so make sure you have the JTAGEN fuse disabled otherwise you won't be able to use that for IO.
Edit: Felix ships this with JTAG disabled so this is only if you've changed the fuse settings.
Mark.
« Last Edit: November 03, 2016, 03:14:58 PM by perky »

simon pearce

  • NewMember
  • *
  • Posts: 2
  • Country: nz
Re: Software Serial bug on MoteinoMEGA? [FIXED]
« Reply #20 on: November 05, 2016, 04:40:17 AM »
Thank you all so much for your replies, have now fixed the issue. It was a software serial issue we fixed with the MCUdude MightyCore version of SoftwareSerial. Seems like it is working well now across a variety of baud rates. Loving using the Moteino it meets our needs exactly and this was really the final piece of the puzzle for us. Now we just need to multiplex the Serial 1 and we'll be doing well.

Once again thank you for your timely and insightful help, it is very much appreciated!

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Software Serial bug on MoteinoMEGA? [FIXED]
« Reply #21 on: November 06, 2016, 08:39:57 PM »
Glad you narrowed it down and solved the problem, thanks for the feedback!

ivars211

  • NewMember
  • *
  • Posts: 16
Re: Software Serial bug on MoteinoMEGA? [FIXED]
« Reply #22 on: February 02, 2017, 02:31:44 PM »
I can confirm, that Standard SoftwareSerial library doesn't work on Moteino mega (at least it didn't for me). As suggested by simon pearce, use MightCore (https://github.com/MCUdude/MightyCore/tree/master/avr/libraries/SoftwareSerial) library.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Software Serial bug on MoteinoMEGA? [FIXED]
« Reply #23 on: February 02, 2017, 03:04:40 PM »
I can confirm, that Standard SoftwareSerial library doesn't work on Moteino mega (at least it didn't for me). As suggested by simon pearce, use MightCore (https://github.com/MCUdude/MightyCore/tree/master/avr/libraries/SoftwareSerial) library.
Can you give more details and the core you were using ?

ivars211

  • NewMember
  • *
  • Posts: 16
Re: Software Serial bug on MoteinoMEGA? [FIXED]
« Reply #24 on: February 03, 2017, 04:11:17 AM »
Can you give more details and the core you were using ?
Hi Felix,

This is with your Moteino mega dualoptiboot bootloader. I was using Arduino IDE 1.6.7 SoftwareSerial library + your updated pins_arduino.h  file and it would compile fine, but software serial won't work.
If I replace that library with MightCore's + your updated pins_arduino.h, everything works as expected.
It could be that I just need to update my IDE version, didn't bother to investigate any further.
« Last Edit: February 03, 2017, 04:16:08 AM by ivars211 »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Software Serial bug on MoteinoMEGA? [FIXED]
« Reply #25 on: February 03, 2017, 08:00:32 AM »
Have you seen the top 2 posts on this page? Others have confirmed the Moteino core fixes this problem. Have you chosen Moteino MEGA as target in the IDE?

ivars211

  • NewMember
  • *
  • Posts: 16
Re: Software Serial bug on MoteinoMEGA? [FIXED]
« Reply #26 on: February 03, 2017, 12:20:29 PM »
Yes. To me, it doesn't matter much which software serial library is being used, as far as it works. Just thought someone else might find that useful.