my configuration
Arduino 3v3 pin connected to ublox (+) pin
ublox (-) connected to BC548 collector pin
BC548 emitter pin connected to Arduino GND
R1 connects Arduino's D9 with BC548 base pin - no voltage divider
ublox TX and RX connected to Arduino's RX and TX respectively
D2 is connected to GND whenever I want to wake Arduino up
What I want to do is to turn ublox on, get FIX, turn ublox off and send Arduino to sleep
The code I use is based on Nick's Gammon code and runs smoothly as long as ublox is not connected.
The problem is when I connect ublox. It goes on, gets FIX and goes off. BUT by the moment I touch a wire to D2 Arduino wakes up and runs the loop.
Please note that this wire is not connected anywhere else, it's a loose wire. Same response if I have already this wire connected.
I tried to connect a flyback/reversed diode in parallel with ublox (+) (-) pins and nothing changed.
I tried pinMode(2, INPUT_PULLUP) in case of floating effect and nothing changed.
I tried to remove extra code and replace it with a simple delay() to debug and nothing changed.
So my fear I have is about a design error with NPN switch circuit. Am I right? Can you help me?
Thank you.
Please draw a schematic. A bad pencil sketch photographed with a phone is better than trying to use words.
I suspect that you will need a PNP transistor to switch the positive power to the GPS. Switching the negative is a bad idea as it's still connected to the Arduino inputs.
MorganS:
Please draw a schematic. A bad pencil sketch photographed with a phone is better than trying to use words.
I suspect that you will need a PNP transistor to switch the positive power to the GPS. Switching the negative is a bad idea as it's still connected to the Arduino inputs.
To be honest I didn't know how to upload a screenshot. Now you can check for the attachment on my initial post. :-[
Putting both Arduino and ublox to sleep means that I am looking for an energy-sufficient project. That's why I use a NPN, otherwise I will need all the time to have the PNP transistor connected to VCC.
The problem is with npn-sw.jpg where Arduino never sleeps/or wakes up endlessly. No button pushed!
Why when I just remove/disconnect the switch, like npn-ok.jpg everything work fine? This is what I can't understand.
In this case it might be wise to switch ground, because the TX/RX pins are permanently pulled up to 5volt.
Base resistor value is wrong.
Using transistor Hfe to calculate base current for a switch is a common beginners mistake.
This is only important when the transistor is used in it's linear region (amplifier).
When the transistor is used as a switch (collector voltage lower than base voltage),
then the base needs 5-10% of the collector current (see Ic/Ib in the saturation graph of the datasheet).
Change that 15k resistor to 1k.
Leo..
Wawa:
In this case it might be wise to switch ground, because the TX/RX pins are permanently pulled up to 5volt.
Base resistor value is wrong.
Using transistor Hfe to calculate base current for a switch is a common beginners mistake.
This is only important when the transistor is used in it's linear region (amplifier).
When the transistor is used as a switch (collector voltage lower than base voltage),
then the base needs 5-10% of the collector current (see Ic/Ib in the saturation graph of the datasheet).
Change that 15k resistor to 1k.
Leo..
Resistor 1k checked.
How can I switch ground at a circuit like this where power supply is a 4AA battery-pack?
I don't understand the relationship of this schematic to the Ublox you described in the first post.
If you use a ground symbol then that's assumed to be system ground. All grounds connect to that. In particular, all of the pins labelled GND on the ATMEGA328 must all be connected to the SAME ground. You should not attempt to operate the chip with one ground floating.
MorganS:
I don't understand the relationship of this schematic to the Ublox you described in the first post.
ublox connector J1
Pin1 is TX pin
Pin2 is RX pin
Pin3 is (+) pin
Pin6 is (-) pin
MorganS:
If you use a ground symbol then that's assumed to be system ground. All grounds connect to that. In particular, all of the pins labelled GND on the ATMEGA328 must all be connected to the SAME ground. You should not attempt to operate the chip with one ground floating.
This is a schematic using fritzing. In breadboard view this ATmega328 is a real Arduino board, no floating GND pins
Check npn-real.jpg and focus on yellow wire. Why this can cause a problem
V-in of a Mega needs at least 6volt for the onboard 5volt regulator to make a stable 5volt.
Four new Alkaline batteries is borderline. Four NiCad batteries is too low.
Why are you using a Mega on batteries.
A Mega is a poor candidate for low power applications.
Many parts on the board can't be turned off (sleep).
Why are you using the main TX/RX pins. They are already used by the USB<>serial chip.
A Mega has three other hardware serial ports that you can use.
Leo..
azelogose:
ublox connector J1
Pin1 is TX pin
Pin2 is RX pin
Pin3 is (+) pin
Pin6 is (-) pin
This is a schematic using fritzing. In breadboard view this ATmega328 is a real Arduino board, no floating GND pins
Check npn-real.jpg and focus on yellow wire. Why this can cause a problem
That is weird. I expected it was just the chip because it's labelled with the name of the chip, its name is "U1" and it has the crystal pins which aren't available on the Arduino headers. If it was labelled "Arduino UNO" or "Arduino Mega" then that would be easier to understand and we can ignore the crystal pins.
Thanks for sending the breadboard view. However that can't be the breadboard of that schematic you posted earlier. The yellow wire goes from pin 2 on the Mega to nowhere in particular. What did you want us to look at with that wire?
I assume the yellow wire is for grounding pin 2 to wake up, it needs to be pulled up to keep it from floating, but do internal pullups work when asleep? Maybe better to use external 27k or so pullup.
outsider:
I assume the yellow wire is for grounding pin 2 to wake up, it needs to be pulled up to keep it from floating, but do internal pullups work when asleep? Maybe better to use external 27k or so pullup.
You are correct; yellow wire is for grounding.
Nice thought! What I can understand by reading ATmega328P datasheet is that there are 3 cases for a pin to be in a tri-state:
i) PUD bit is HIGH,
ii) PORTxn is LOW,
iii) during RESET
Update: Anyhow ATmega328P arrived yesterday and everything works fine. Not a priority right now to solve the MEGA board mystery.