LowPowerLab Forum

Hardware support => MoteinoMEGA => Topic started by: gregcope on May 11, 2015, 03:44:36 PM

Title: Moteino Mega and Software serial
Post by: 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;


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....
Title: Re: Moteino Mega and Software serial
Post by: TomWS on May 11, 2015, 03:56:04 PM
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
Title: Re: Moteino Mega and Software serial
Post by: Felix on May 11, 2015, 04:05:31 PM
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.
Title: Re: Moteino Mega and Software serial
Post by: gregcope on May 11, 2015, 04:15:20 PM
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.

Title: Re: Moteino Mega and Software serial
Post by: Felix on May 11, 2015, 04:24:58 PM
greg,

Here are some links for you to read on:

https://lowpowerlab.com/forum/index.php/topic,345.msg4435.html#msg4435
https://lowpowerlab.com/forum/index.php/topic,955.msg6074.html#msg6074
http://playground.arduino.cc/Main/PinChangeIntExample
Title: Re: Moteino Mega and Software serial
Post by: gregcope on May 11, 2015, 04:26:09 PM
Many thanks.
Title: Re: Moteino Mega and Software serial
Post by: gregcope on May 19, 2015, 06:07:35 PM
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?
Title: Re: Moteino Mega and Software serial
Post by: 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!"

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
Title: Re: Moteino Mega and Software serial
Post by: TomWS on May 19, 2015, 07:30:55 PM
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
Title: Re: Moteino Mega and Software serial
Post by: gregcope on May 20, 2015, 02:28:10 AM
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.
Title: Re: Moteino Mega and Software serial
Post by: TomWS on May 20, 2015, 08:23:50 AM
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
Title: Re: Moteino Mega and Software serial
Post by: gregcope on May 20, 2015, 03:55:59 PM
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.
Title: Re: Moteino Mega and Software serial
Post by: TomWS on May 20, 2015, 04:14:43 PM
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
Title: Re: Moteino Mega and Software serial
Post by: gregcope on May 20, 2015, 04:38:54 PM
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/ (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?


Through hole mount - yes please - KISS at the moment!
Title: Re: Moteino Mega and Software serial
Post by: TomWS on May 20, 2015, 05:38:11 PM
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

Title: Re: Moteino Mega and Software serial
Post by: gregcope on May 21, 2015, 02:53:16 AM
Many thanks.  I can get those with free shipping;

http://m.rs-online.com/h5/mobile/uk/catalog?url=%2Fweb%2Fp%2Fproducts%2F5429478%2F?cm_mmc=UK-PPC-0914-_-google-_-3_MPN_Phrase-_-1380f9f1-0ad9-aac8-dbd9-00001b3cce34&gclid=CIfG1fCc0sUCFcZ02wodMg8ASg

One quick Q;

Why that one?  What is the difference (in summary) between that one and the others so that I might learn something.

One challenge in this area is that I have read quite allot, and there seems no consensus on parts ...
Title: Re: Moteino Mega and Software serial
Post by: TomWS on May 21, 2015, 08:39:27 AM
Quote from: gregcope on May 21, 2015, 02:53:16 AM
Many thanks.  I can get those with free shipping;

http://m.rs-online.com/h5/mobile/uk/catalog?url=%2Fweb%2Fp%2Fproducts%2F5429478%2F?cm_mmc=UK-PPC-0914-_-google-_-3_MPN_Phrase-_-1380f9f1-0ad9-aac8-dbd9-00001b3cce34&gclid=CIfG1fCc0sUCFcZ02wodMg8ASg

One quick Q;

Why that one?  What is the difference (in summary) between that one and the others so that I might learn something.

One challenge in this area is that I have read quite allot, and there seems no consensus on parts ...
Unfortunately, in the Arduino world, a lot of information is based on 5V Arduinos.  The transistors you read about were fine if driven from a 5V processor but they aren't really low enough Vgsth for a 3.3V processor (which is much harder to accomplish on a power FET).  I was able to use the 2N7000 simply because this circuit draws very little power from the transistor so, even though it's operating in the weak part of its 'knee', it's still good enough for this app.

Secondly, the power transistor you have is an 'N' channel part and, for this circuit, you need a 'P' channel part because you are switching the positive rail rather than ground.  Also the power transistor you have has 4 times the gate capacitance of the one I recommended - largely due to its increased current capacity (which you don't need for this case).

However, the primary driver to select this particular transistor is that you wanted a through-hole transistor.  I could find a zillion surface mount (well, maybe not that many) transistors that are low threshold  and support currents >500mA without going to a multi-digit Amp capacity.  It wasn't so easy finding an through hole transistor that would switch >500mA and not end up support tens of amps. 

The other criteria was that it had to be something you could get on your side of the planet.  After that, it came down to price  ;)

As an example of the 'knee' I mentioned earlier, I've attached two clips from two datasheets, both N channel transistors.  The first is from the 2N7000 data sheet, the second is from a transistor I'm using on a project.  In the case of the 2N7000, it doesn't even think about conducting current until the Vgs gets around 3V, take a look at the second one, it starts conducting a significant amount of current at 1.25V...  Another useful curve, which I trust more, but isn't included in the 2N7000 datasheet is RdsOn vs Vgs.  This really shows where the 'knee' is.

Tom
Title: Re: Moteino Mega and Software serial
Post by: gregcope on May 21, 2015, 04:10:33 PM
Thanks Tom.  Those P-Mosfets are cheaper than the others!

Last Q... (sorry);

What would you recommend (from the two N Mosfets and the P-Mosfet) for switching/powering on/off from a digital pin a 25mA GPS or a (upto) 1A GPRS modem?


Title: Re: Moteino Mega and Software serial
Post by: TomWS on May 21, 2015, 06:54:01 PM
Quote from: gregcope on May 21, 2015, 04:10:33 PM
Thanks Tom.  Those P-Mosfets are cheaper than the others!

Last Q... (sorry);

What would you recommend (from the two N Mosfets and the P-Mosfet) for switching/powering on/off from a digital pin a 25mA GPS or a (upto) 1A GPRS modem?
For your GRPS modem, since it draws so much current, I would use the same circuit (from 12V) to a linear voltage regulator to drop down to the GPRS modem voltage.  I think switching regulators, unless they are VERY GOOD regulators, will be too noisy and I don't think you have it on that often to worry too much about wasted power.  Doesn't that GPRS radio have an enable pin that drops power to virtually nothing?

For the GPS receiver, I don't think you have a proper MOSFET in your 'inventory'.  I'd use a PNP bipolar transistor (PN2907 or equivalent).  Emitter to 3.3V, base driven through a 2.7K resistor from a Moteino pin (low to turn ON), and collector driving your GPS device.

You might want to look into getting some SOT23 breakout boards. Sparkfun and your very good friend Felix sells these.  This will allow you to use these very handy surface mount MOSFETs without having too much breadboarding difficulty. 

Tom

Title: Re: Moteino Mega and Software serial
Post by: gregcope on May 23, 2015, 09:04:27 AM
Sorry Tom.  You've lost me.

Looking at the spec of the XXX Do I need the 2N7000 to drive it's gate as I assume this bit;

Gate-Source Threshold Voltage VGS(th) VDS = VGS, ID = - 250 μA - 2.0 - - 4.0 V

I assume that means that a 3.3v Digital pin on a Moteino should be able to drive that Gate easily?

From here; http://docs-europe.electrocomponents.com/webdocs/0791/0900766b8079172b.pdf

For simplicity can I not just use this everywhere?
Title: Re: Moteino Mega and Software serial
Post by: TomWS on May 23, 2015, 09:55:38 AM
Quote from: gregcope on May 23, 2015, 09:04:27 AM
Sorry Tom.  You've lost me.

Looking at the spec of the XXX Do I need the 2N7000 to drive it's gate as I assume this bit;

Gate-Source Threshold Voltage VGS(th) VDS = VGS, ID = - 250 μA - 2.0 - - 4.0 V

I assume that means that a 3.3v Digital pin on a Moteino should be able to drive that Gate easily?

From here; http://docs-europe.electrocomponents.com/webdocs/0791/0900766b8079172b.pdf

For simplicity can I not just use this everywhere?
I'm not sure what you're struggling with.  There were two places that the circuit using this transistor was used, both of them require the 2N7000 to provide the voltage shift so that the P-Channel MOSFET's gate can be pulled up to 12V.

What am I missing?
Title: Re: Moteino Mega and Software serial
Post by: gregcope on May 23, 2015, 10:31:59 AM
My own stupidity/inexperience.