TeensyLC SPI, does hardware require MISO?

Status
Not open for further replies.
Yes. Just use pinMode(12, OUTPUT) any time after SPI.begin() to take control of the pin again. The other modes like INPUT & INPUT_PULLUP work too.
 
Hey Paul, so this worked fine when I made the pin an output, but I can't get pin 12 to work with Encoder.h. I had both my encoders working fine, but because of board trace routing, I ended up having to switch to using pin 12 as an encoder pin. I changed my breadboard proto accordingly and now read() gives me unreliable results. If I add pinMode(12, INPUT) to setup(), rotating the encoder doesn't work at all. I'm using an Adafruit SSD1306 display via SPI, so I put pinMode(12,INPUT) after display.begin(), assuming that would occur after SPI.begin(). In short, Encoder works fine on pins other than 12, and the only thing touching pin 12 is SPI.

Similarly, if I call pinMode(x,INPUT) for another encoder's pins, it stops working as well. So it seems like touching an Encoder's pins after declaring Encoder my_encoder(pina,pinb) breaks it.

This has taken me down a small rat hole... wanting to see what Encoder.h is doing internally, I can't find it. The sketch won't build unless I include "Encoder.h", but that header doesn't appear to be in my file system anywhere. Are there hidden/precompiled headers in Teensyduino?

Any advice much appreciated.
 
It is a library installed with TeensyDuino

See the install directory for :: ...\hardware\teensy\avr\libraries\Encoder\Encoder.h
 
If I move the Encoder declaration inside of loop() it works fine.
This is not really standard Arduino style though eh? All the sketches I've seen declare everything at the top of the file.

Code:
void loop()
{
    static Encoder enc_left(ENC_LEFT_DT_PIN, ENC_LEFT_CLK_PIN);
    static Encoder enc_right(ENC_RIGHT_DT_PIN, ENC_RIGHT_CLK_PIN);

    ServiceLeftEncoder(enc_left);
    ServiceRightEncoder(enc_right);

    (...)
}
 
Status
Not open for further replies.
Back
Top