Moteino Mega and Software serial

Started by gregcope, May 11, 2015, 03:44:36 PM

gregcope

HI All,

I need Software Serial on the Moteino Mega to work logic is as follows;


  • INT0 D10 Used for a button to drive a hardware interup and wake up the Moteino
  • INT1 D11 Used for a PIR to drive a hardware interup and wake up the Moteino
  • INT2 D2 Used by the transeiver
  • Ser0 D8 Used by a GPS, but also handy for Serial debugging println
  • Ser0 D9 Used by a GPS, but also handy for Serial debugging println

Hence I need Software Serial to work so that I can connect a GPRS / GSM modem to send SMS messages.

Any ideas?

Googling has thrown up lots of messages, but no answer....

TomWS

Quote from: gregcope on May 11, 2015, 03:44:36 PM
HI All,

I need Software Serial on the Moteino Mega to work logic is as follows;


  • INT0 D10 Used for a button to drive a hardware interup and wake up the Moteino
  • INT1 D11 Used for a PIR to drive a hardware interup and wake up the Moteino
  • INT2 D2 Used by the transeiver
  • Ser0 D8 Used by a GPS, but also handy for Serial debugging println
  • Ser0 D9 Used by a GPS, but also handy for Serial debugging println

Hence I need Software Serial to work so that I can connect a GPRS / GSM modem to send SMS messages.

Any ideas?

Googling has thrown up lots of messages, but no answer....
Why don't you keep Ser1 on pins 10 and 11 and use pinChangeInterrupt on other pins for your Wake Events?

Seems a lot simpler than hacking in a software uart...  IMO.

Tom

Felix

The MoteinoMEGA uses the Atmega1284p which has a total of 3 external hardware interrupts. One is tied to the transceiver. The other 2 are shared with the Ser1 hardware serial unfortunately.
BUT ... you can use PCINT interrupts on any other pin - not sure if this is what Tom meant. The difference is that you will have to check manually which PIN caused the interrupt. If you only have 2 possible interrupt sources on 2 pins then that should be pretty simple.

gregcope

Gents,

Thanks for the prompt response ...

Sorry - being stupid.

Are you saying I can wake from sleep by NOT using INT0/INT1 ie any digital pin and set a pinChangeInterrupt?

Any guides/suggestions on checking which pin might have fired?  Is something that would be done in an ISR (ie check which PIN is high?)?

Sorry - Looking for a bit of guidance here as I a newbie.



gregcope


gregcope

After lots of thinking / reading on Pin Change Interrupts they appear on 4 groups on the Atmega1284P;

http://www.atmel.com/images/Atmel-8272-8-bit-AVR-microcontroller-ATmega164A_PA-324A_PA-644A_PA-1284_P_datasheet.pdf (pages 67->)

From what I understand;

PCIE3 PCINT31:24 - Mostly Analog Pins
PCIE2 PCINT23:16 - Has Flash on D23
PCIE1 PCINT15:8   - Has Serial0/1 on D8->D11
PCIE0 PCINT7:0     - Has the transceiver on D2, D4->D7

I want to attach interrupts for waking from sleep - the Hardware Interrupts pins are already committed as I need the serial ports e.g. Serial1 (INT0 and INT1), whilst the radio uses D2 (INT2).  Which I think rules out the PCI0 and PCI1.

I want to attach two interrupts to wake from sleep, for a PIR and a Button.

Question 1: If I plan to use quite a few Digital pins for IO etc... and If I use pins that are also in an Pin Change group, any Output I believe these would also fire interrupts.  And hence I should avoid using these?

Is this correct?


Question 2:  If want to have 4 Analog pins to do occasional ADC stuff (ie only on when needed to take readings) (temp, level and voltage x2 A0 through A3)).  Will changes on these as input ADC pins, fire the Pin Change Interrupts?

Will this work or will I go into some sort of interrupt loop?


Question 3: Stop worrying and cope with interrupts firing allot and just deal with issues in software? - IE ignore any Pins firing that I do not care about

I could put the button and PIR on pins D28/D29 which is in the top group.  Most of the time the Analog pins will be off as I only take readings every so often for 20Msecs or so - ie enough to settle - every 2x8sec sleep cycles.

Example Digital output pins needed;
1. GPS power on (Mosfet) - D0
2. GPRS modem power on (Mosfet) - D1
3. Temp power on (direct from pin) - D3
4. Buzzer (direct from pin) - D12
5. Power button LED (direct from pin) - D13
6. Charger power on (Mosfet) - D14
7. Level meter power on (direct from pin) - D16

Leaves me D17-D22 spare

Thoughts?

TomWS

Greg, From the first line of the Hitch-hiker's Guide to the Universe: "Don't Panic!"

Good advice in this case... 

Rule number one: Every pin that is capable of generating a pinchange interrupt has a corresponding mask pin to enable it.  If you don't want to enable that pin, don't flip the corresponding bit.  Unwanted interrupts taken care of.

Rule number two:  Life is simpler if you simply look at the great charts that Felix provides for each of his boards.  For the Mega: https://lowpowerlab.com/moteino/#pinoutMEGA

Avoid all Dxx pins marked in red text.  Felix 'owns' them.  On the Mega, avoid D8-D11 'cause you want these for serial lines.  Net: Anything else is YOURS! WooHoo!

Tom

TomWS

Also, if you don't want to do anything special to identify which pin caused the interrupt (even though it's trivial to do), put your two pins in two different groups.  If you only enable one pin per group, then it's obvious which one caused the interrupt.

Frankly, I'd prefer to group them in the same group so that I'd only need one interrupt handler.

Tom

gregcope

Quote from: TomWS on May 19, 2015, 07:26:15 PM
Greg, From the first line of the Hitch-hiker's Guide to the Universe: "Don't Panic!"

I find the no.42 very useful too!

Quote from: TomWS on May 19, 2015, 07:26:15 PMRule number one: Every pin that is capable of generating a pinchange interrupt has a corresponding mask pin to enable it.  If you don't want to enable that pin, don't flip the corresponding bit.  Unwanted interrupts taken care of.

Ahhhhh.

I thought than enabling any pin in a group, caused them all to fire interrupts on any pin change,  to one Interrupt call routine.

Simples.  Will hack some examples later today.

Thanks again TomWS.

PS My thinking has solidified on the other thread/question.  I will run a 12v -> 5v regulator on a Mosfet, so that I can switch it on to power a 5v battery charger when the battery gets low...  I can do this parasitically when the 12v line looks like it is charging, or when required.  Lots of advantages - the 12v regulator can run efficiently at 500ma when charging, and all the regulator/charger need only run when required futhur saving power.

TomWS

Quote from: gregcope on May 20, 2015, 02:28:10 AM
<...snip>
PS My thinking has solidified on the other thread/question.  I will run a 12v -> 5v regulator on a Mosfet, so that I can switch it on to power a 5v battery charger when the battery gets low...  I can do this parasitically when the 12v line looks like it is charging, or when required.  Lots of advantages - the 12v regulator can run efficiently at 500ma when charging, and all the regulator/charger need only run when required futhur saving power.
Sounds good.  The MOSFET will probably draw a lot less quiescent current than the enable on the original regulator you were considering.  Just keep an eye on the surge current when the regulator is turned on, make sure your rise time on the MOSFET Vgs is fast enough that you don't spend too much time (<1mS) in the linear region and you should have a reliable system.

Happy Sailing!

Tom

gregcope

Quote from: TomWS on May 20, 2015, 08:23:50 AMSounds good.  The MOSFET will probably draw a lot less quiescent current than the enable on the original regulator you were considering.  Just keep an eye on the surge current when the regulator is turned on, make sure your rise time on the MOSFET Vgs is fast enough that you don't spend too much time (<1mS) in the linear region and you should have a reliable system.

Happy Sailing!

Tom

Ok - you lost me there ...

I have some 2N7000s and FQP30N06Ls.  The latter probably for use on voltage sensing and on/off;

http://cdn.sparkfun.com/datasheets/Components/General/FQP30N06L.pdf

I have new found respect for hardware designers ... so much to cover/learn.

TomWS

Greg,
I don't think Sparkfun has the transistors you need.  What other electronic suppliers would you normally use?  I'll try to pick something that would be appropriate.  I assume you would prefer through-hole mount rather than surface mount.  Also, I need to know the input current (on 12V side) of your voltage regulator at full load.

Tom

gregcope

Quote from: TomWS on May 20, 2015, 04:14:43 PM
Greg,
I don't think Sparkfun has the transistors you need.

Np.  I got those after reading this http://jeelabs.org/2013/05/17/zero-powe-battery-measurement/ and it mentioned

    low turn-on voltage (called a "logic level MOSFET")

Quote from: TomWS on May 20, 2015, 04:14:43 PMWhat other electronic suppliers would you normally use?  I'll try to pick something that would be appropriate.  I assume you would prefer through-hole mount rather than surface mount.  Also, I need to know the input current (on 12V side) of your voltage regulator at full load.

Tom

To be honest I am a real noobee - I have used; RS/Farnel/ebay/digikey (although postage is high for small orders digikey)

Have not chosen a voltage regulator.  Can you recommend one?


  • Input voltage is likely to be below 16V but probably more for a margin of error.  It is a normal 12V circuit that will be around 12.7V most of the time, but up to 14.5V when chargers / alternators are on
  • Something that can take upto 28V would be handy for 24V systems
  • I want to measure that input voltage to report on it- hence the jeelabs link/ideas, and also flip the regulator/5v charger on when required

Through hole mount - yes please - KISS at the moment!

TomWS

Greg,
I've attached a schematic for a driver to turn on power to your voltage regulator.  I found a P-MOSFET transistor that is acceptable and reasonably priced on the Newark/Farnell site, hopefully you can find it in the UK.  The key is you need something that is rated for at least 500mA AND has low input capacitance (otherwise you'll get slow turn on/off or consume extra power).  The P-MOSFET is driven from your 2N7000 which is connected to your Moteino.  Since the gate voltage is 12V, a sensitive gate voltage on the P-Channel FET isn't necessary.  The 2N7000 isn't what I would call a low voltage controlled gate, but it will work in this case.

Re power supply, since you're stepping down from 12V to 5V only during battery charging, practically any regulator will do it and you can get some real inexpensive ones if you look for LM2596 (ebay has a BILLION of them!).

Tom