Teensy3.1 Audio adaptor with 12 touch pins

Status
Not open for further replies.

Teenfor3

Well-known member
I have teensy3.1 connected using the standard pins as per the documentation to the audio adaptor board. I don't use the VOL pin 15 for volume I use it as touch input. I am using 8 touch pins (0, 1, 15, 16, 17, 25, 32, 33) and all works OK as touch pins, but I now want to use all 12 of the touch pins on the teensy, as touch pins. Pins 22 and 23 are touch but are currently used as LRCLK and TX for the I2S output from Teensy to audio adaptor. Pins 18 and 19 are touch but currently used for SDA0 and SCL0 for I2C control of the adaptor. I was wondering can I change the I2C to use Teensy pins 29 and 30 as this is SDA1 and SCL1. I presume I just need to connect the adaptor pins to 29 and 30 but where do I re-define the software.
and same for the I2S, what other pins can be used for I2S instead of 22 and 23. I presume what is needed it similar to what is done for the SD socket SPI pins 7 and 14.
Any help appreciated please.
 
From earlier post....
"Pins 22 and 23 are touch but are currently used as LRCLK and TX for the I2S output from Teensy to audio adaptor."
Can anyone please tell me where I look in the libraries etc to see where Pins 22 and 23 are assigned for use and can I change to use the unused pins 20 and 21 instead and free up 22 and 23 for touch control.

Similarily....Pins 18 and 19 are touch but currently used for SDA0 and SCL0 for I2C control of the adaptor. I was wondering can I change the I2C to use Teensy pins 29 and 30 as this is SDA1 and SCL1 and appears to be free on teensy.
 
Last time I looked the pins for I2S are configured in Audio/output_i2s.cpp in AudioOutputI2S::config_i2s() routine but they may be (re-)configured elsewhere in the Audio Library as well and it is a wee while since I scrutinised the code in the library that much.

Whether or not those can be shifted exactly where you want to shift them is a story told in the MK20DX256VLH manual (http://www.pjrc.com/teensy/K20P64M50SF0RM.pdf), unfortunately it can be a fairly complicated read at times.

I haven't looked for where any portion of the items referenced by the Audio Library configures I2C but I am willing to bet that it is in the Wire library, basically because that is where it belongs. Selecting the alternative pins for those may be supported by the library itself but if not it is a matter of finding and understanding the appropriate portion of that manual I linked to a minute ago to find out how to change it.

Sorry I've not the time to delve into it and provide any kind of examples etc, if it is over your head then just bump this thread once a day with something like "please help me more!" and someone with time (and willingness to use it for you) will hopefully turn up sooner than later.
 
Thanks Rob for your reply.....
I have been searching since for articles relating to configuring pins used and didn't find much about changing then in the wire library and then came across the following regarding a new I2C library for teensy3. I assume to replace the wire library..???.

http://forum.pjrc.com/threads/21680-New-I2C-library-for-Teensy3.

It is well documented but for me it is hard reading. What I did was download it and put it in libraries folder. Then comment out ( #include wire.h ) from my sketch and insert ( #include i2c_t3.h ). I also did same in control_wm8731.ccp and control_sgtl5000.ccp.

I also added the line to my sketch.....

// Wire
Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_INT, I2C_RATE_400);

These are the pins (18 and 19) that I had been using before any changes.
I got errors compiling relating to sgtl5000.ccp line 546, so I commented out the line 546 to try it again....

The line 546 says...
if(wire.endTransmission(false) != 0) return 0;

Im sorry I didn't take a note of the actual error messages.....

I compiled again and got no errors and tried if teensy was still working on the old pins.....and all works OK. with the new i2c_t3.h library except the line 546 is still commented out.

I changed the line in my sketch to the following to enable pins 29 and 30 and the sketch compiles OK.

// Wire1
Wire1.begin(I2C_MASTER, 0x00, I2C_PINS_29_30, I2C_PULLUP_INT, I2C_RATE_400);

I don't know if it is working on the new pins until I change the wiring. It may be a few days until I get back to it, but I think it will work..????.
I don't know if there is anything else I need to change until I try it.

Hopefully that will free up 2 touch pins and give me 10 now.

I didn't find much on the I2S pins. I2S as such is not shown on the coloured cards giving the pinouts.....maybe its any gpio pin can be used...
I will need to do a bit more searching...........Thanks again for your help....
 
That alternative i2c_t3 library should be beaut by all accounts I've heard.

Rather than removing the entire line throwing the error in control_sgtl5000.cpp please change it to
Code:
if(wire.endTransmission(I2C_NOSTOP) != 0) return 0;
And if that fails for whatever reason it may as well become
Code:
if(wire.endTransmission() != 0) return 0;
Better if it works with I2C_NOSTOP (because that reflects the functionality that Paul gave the original line better) but it will be better to have the second version I provide in this post than nothing there at all.

The I2S pins may not be re-assignable, if there are alternative pins for them then searching for things like I2S_LRCLK may help you come across the information required - Paul and others should be able to state categorically whether or not there are alternatives due the familiarity I expect they have gained with the appropriate data; I sort of feel like flicking through the most relevant section to see if it is a very arduous a task to determine one way or t'other but I have plenty to do as it is, sorry.
 
Haven't got back to it yet but thanks for your guides. Ihave looked at the manual seems like upto 16 touch can be configured ts1 to ts15. Don't rally know if this is possible. But I suppose I have 2 options move the i2s or setup 2 additional touch pins. Anybody any ideas on that please.
 
Well if you can't reconfigure which pins are touch pins and can't move the i2c pins, Adafruit does sell some off board touch sensors:

Of course another solution is to use a second Teensy and communicate with the master via serial (uart), i2c, or other methods.
 
Last edited:
Yes seem good breakout. But I want if possible to minimise the number of boards. The only problem I may see is the time needed to read all sensor pads to know which ones touched or not touched. Would it be as fast as teensy. On teensy I use a for next to read all 8 as quickly as possible and set a bit in an 8 bit variable to give me a value for each read scan. And this still takes a few milli seconds 12 touch will take longer. Is there any quickeer way of reading touch sensors than using touchread. I want to read the current status of all sensors at one time. I know its not possible at exactly one instance but read as quick aspossible
 
I am back at base again with teensy3.1. Have changed the wiring to suit the changes to the I2C pins from "18 and 19" to "29 and 30" and all works but I did not need to add the statements I mentioned in earlier post for "Wire1" in my sketch. I didnt make any changes to my sketch except "#include i2c_t3.h" added and comment out "wire.h". also add touchread for the new pins.

But.......I had to change all statements for "wire" in ControlSGTL5000.ccp to "wire1"......? ? ? This is in the Audio library.

Is this the correct thing to do?....It is making changes to a Library file..??????. are there any better solutions?

I now have 10 touch pins (0, 1, 15, 16, 17, 18, 19, 25, 32, 33) and the I2C for control of the audio-adaptor now working on pins 29 and 30.

I also still want to move the I2S from pins 22 and 23 to free these up as touch or move the touch function to another 2 pins.....
I haven't got this investigated any further yet....

I would welcome if anyone can post details of any good background reading to help me understand reading the library files.......Thanks.....
 
I have been investigating getting the touch pins 22 and 23 available....currently 22 and 23 are used by the I2S audio port, pin 22 is TX and pin 23 is LRCLK.

Pins 20 and 21 are free if they would work...? ? ?.

I assume it is something to do with these lines copied from OUTPUT_I2S.cpp from the Audio Library

===================================
void AudioOutputI2S::begin(void)
{
//pinMode(2, OUTPUT);
block_left_1st = NULL;
block_right_1st = NULL;

// TODO: should we set & clear the I2S_TCSR_SR bit here?
config_i2s();

CORE_PIN22_CONFIG = PORT_PCR_MUX(6); // pin 22, PTC1, I2S0_TXD0

===================================
And also these lines.....
==================================================

// configure pin mux for 3 clock signals
CORE_PIN23_CONFIG = PORT_PCR_MUX(6); // pin 23, PTC2, I2S0_TX_FS (LRCLK)
CORE_PIN9_CONFIG = PORT_PCR_MUX(6); // pin 9, PTC3, I2S0_TX_BCLK
CORE_PIN11_CONFIG = PORT_PCR_MUX(6); // pin 11, PTC6, I2S0_MCLK

==============================================================

I changed the line for Pin22 to read as for Pin20 and connected Teensy3.1 pin20 to Audio adaptor Pin22.
It compiled without error but didn't get any sound from audio adaptor board.

CORE_PIN22_CONFIG = PORT_PCR_MUX(6); // pin 22, PTC1, I2S0_TXD0
changed to.. CORE_PIN20_CONFIG = PORT_PCR_MUX(6); // pin 22, PTC1, I2S0_TXD0

===============================
Would be grateful if anyone can help Please......
 
Actually I have got the I2S0_TXD0 now working on the alternative pin3 of teensy.

I looked up the table of pin functions in chapter 10 of the ref. manual, found it works on PTA12 which is pin28 of the chip ans pin3 of teensy3.1
So changed.......CORE_PIN22_CONFIG = PORT_PCR_MUX(6); // pin 22, PTC1, I2S0_TXD0
to............. CORE_PIN3_CONFIG = PORT_PCR_MUX(6); // pin 3, PTA12, I2S0_TXD0

and connected pin3 teensy3.1 to pin22 of audio adaptor...and it worked.

Now hopefully the touch on pin22 teensy will now work........
 
Yes it worked......connected pin22 to a touchpad and worked ........no other config needed.

and discovered I only need 11 touch pins.......Its like the fence and fence posts.......12 posts and only 11 spaces.....
I only need 11 pins to get 12 things happening......because there is the condition when all are touched and when none are touched.

I will keep reading the Ref. Manual..........RTFM..............Thanks for pointing me in the right direction..............
 
I was able to get faster touch results by only calling touchRead once to read all 12 pins, and by futzing with the current, oversampling, etc. More info. The tradeoff is less sensitivity, but I basically wanted a boolean result of whether the sensor was being touched or not.
 
Thanks for reply...
Looks like a good possibility....I don't know if I understand it all but will give it a try.....the "less sensitivity" may be a benefit as well.
One of the problems I have is erratic switching if the pad is lightly touched..............
I too just want a boolean result depending on which pad or combination of pads are touched......and also not to switch in and out if nearly touched or touched lightly.
 
Status
Not open for further replies.
Back
Top