Trinket cross-talk between pins 3 and 4

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
craigim
 
Posts: 14
Joined: Sat Jan 18, 2014 5:20 pm

Trinket cross-talk between pins 3 and 4

Post by craigim »

I am making a small clock for my office. I have a trinket 3V, a chronodot, a 7-segment LED display with backpack, a phototransistor, and some switches and resistors.

I'm not sure how to post an image, so bear with me.

USB+ is connected to the + pin on the backpack
Pin 0 (SDA) is connected to the data pins on the chronodot and the backpack
Pin 2 (SCL) is connected to the clock pins
3V is connected to the + pin on the chronodot
GND is connected to the ground pins

So far so good. However, I wanted to add a button so that I could change the hour and a phototransistor that I could use to dim the clock when the room is dark.

From 3v I put in a 10k resistor to the phototransistor collector, then to ground. Also on the collector I put a switch that connects to pin 3

There is a push button switch connecting pin 4 to ground. Pin 4 is set as a digital input with an internal pullup resistor.

What I want to happen: on each loop the analog voltage on pin 3 is read into a 30 second buffer and the clock brightness is set based on the average value of the buffer. If the button is pressed, pin 4 goes low the hour is incremented. The switch on the photosensor is so that it won't mess with the USB when I'm programming.

What actually happens: when the room gets bright enough, the hour become a second hand, incrementing once per second, probably because pin 4 is being pulled low.

Everything is being powered from a 5V/850 mA USB power supply (I think it was originally intended for an old Kindle).

Do I need an extra pullup resistor on pin 4? Do I need to put resistors on the clock and data lines? Do I need to supply more power?

User avatar
craigim
 
Posts: 14
Joined: Sat Jan 18, 2014 5:20 pm

Re: Trinket cross-talk between pins 3 and 4

Post by craigim »

The solution was to move the button to pin 1. Whenever I put light onto the phototransistor hooked to pin 3, the voltage on pin 4 would drop below 1 V. Pin 1 seems to be much better isolated.

User avatar
hiduino
 
Posts: 862
Joined: Sat Sep 01, 2012 7:05 pm

Re: Trinket cross-talk between pins 3 and 4

Post by hiduino »

That shouldn't be happening, unless there is some kind of power problem or something not being setup correctly in your code. Can you post your code?

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Trinket cross-talk between pins 3 and 4

Post by Franklin97355 »

Pins 3 and 4 are tied to the USB port and have other components connected. Check the schematic as this might be your problem.
Attachments
2014-09-23_13h00_00.png
2014-09-23_13h00_00.png (14.17 KiB) Viewed 301 times

User avatar
hiduino
 
Posts: 862
Joined: Sat Sep 01, 2012 7:05 pm

Re: Trinket cross-talk between pins 3 and 4

Post by hiduino »

Tested pin #4 with INPUT_PULLUP while the USB is plugged in. It does appear that the USB connection will pull pin #4 low. Also toggling pin#3 while the USB is plugged in tends to drive the USB enumerator on the computer crazy.

With the 3V Trinket powering it via BAT+ (no USB cable) will allow you to use pin#4 as an input with INPUT_PULLUP working correctly. Actually, just noticed that the schematics for the 3V Trinket does not have any zener diodes since it is already operating at 3.3V. So you should have no issue as long as you don't use it with the USB power.

With the 5V Trinket powering it via BAT+ (no USB cable) does not work with pin#4 as an input with INPUT_PULLUP. The internal high level on pin#4 is enough to trigger the zener diode and bring the pin low. This is probably because the internal pullup does not supply enough current to keep the zener at 3.6v, it is closer to around 2v. This is enough to register as a low level. Using an external pull-up resistor does supply enough current to allow the zener to stay above 3v allowing it to register as a high level.

User avatar
craigim
 
Posts: 14
Joined: Sat Jan 18, 2014 5:20 pm

Re: Trinket cross-talk between pins 3 and 4

Post by craigim »

I thought I had turned on notifications, so I didn't realize there was followup. I think I came to some of the same conclusions, though.

The behavior that hiduino observed in the first paragraph is exactly what I see.

For my digital input into pin 4, I switched to using pin 1 instead and that solved that problem. I also switched to using the 3v output to power the 7-segment LED backpack instead of the USB+ output. For my analog phototransistor input into pin 3, I put in a slider switch so that I could disconnect the phototransistor while programming. Doing that, I can power my clock using the USB cable plugged into a phone charger and it (almost) works just fine.

I now have everything nicely soldered together and fit into a die-cast aluminum hobby box. However, I have discovered that with the slider switch set to on, if I plug the USB into wall power, when the Trinket comes on it sees that there is a signal of some sort on the USB port and rather than booting up the sketch it sits and waits. Unfortunately that means that whenever I want to plug my clock in I have to unscrew the cover, slide the switch off, plug it in, and then slide the switch back on before screwing the cover back on. This is a little inconvenient. Alternatively, I can hold my thumb over the light sensor and it will come on, although if the power goes off, this will only work if it comes on at night with the lights off or during a total solar eclipse.

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”