Tympan / Tympan_Library

Arduino/Teensy Library for Tympan Open Source Hearing Aid
MIT License
116 stars 31 forks source link

Using the AIC CODEC Shield as Main sound processor #67

Open zvikapika opened 1 year ago

zvikapika commented 1 year ago

Due to Tympan Rev E being sold out, I have been trying to connect the AIC CODEC Shield directly to a Teensy 4.1 board, with no luck. The connections I have made are according to the documentation and the Rev E PCB, as following:

Shield                                 |               Connected To
**First row (from left)**
1.8V                                                  Voltage regulated 1.8V (stepped down from on 5V of Teensy)
IN1 RIGHT                                             NC
IN1 Left                                              NC
LINE OUT LEFT                                         NC
LINE OUT RIGHT                                        NC
GND                                                   Teensy GND

**Second row**
MIC BIAS                                              NC
MCLK                                                  Teensy D23
BCLK                                                  Teensy D21
WCLK                                                  Teensy D20
GND                                                   Teensy GND

**Third row**
PDM CLK                                               NC
PDM DAT                                               NC
SDO                                                   NC
SDI                                                   NC
SCK                                                   NC
CS                                                    NC

**Fourth row**
3.3V                                                  Teensy 3.3V
DOUT                                                  Teensy D6
DIN                                                   Teensy D32
SDA2                                                  Teensy D18 (Wire2 changed to Wire, also tried Wire1)
SCL2                                                  Teensy D19 (same)
GND                                                   Teensy GND

Also, visual legend of the connections made can be found here: https://www.dropbox.com/s/wg9cwudwld1ig52/AIC%20CODEC%20Shield%20Connections.png?dl=0

Upon loading the AudioPassThru sketch, I am getting no sound on the headphones connected to the shield, and serial monitor shows the following error messages:

AudioPassThru: Starting setup()... AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: INFO: Read Page. Page: 0 Reg: 27. Failed to go to read page. Could not go there. AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During writeRegister(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 AudioControlAIC3206: Received Error During goToPage(): Error = 2 Setup complete. Running...

If there is any way we can get this to work, I'd appreciate any help at all. This project is done during a hackathon in Nigeria taking place this week, and the team is very excited to see the project work. However, so far we haven't been able to do so... Thanks in advance for any pointer or help, Zvika

chipaudette commented 1 year ago

Hello Zvika!

The type of errors that you're seeing tell me that the AIC3206 is not responding to the Teensy. Typically, the problem is that the "reset" pin of the AIC3206 is not connected back to the processor (to the Teensy). So, I looked at the connection map that you provided. I think that I see the problem. Or, at least, I see one problem.

**Second row**
MIC BIAS                                NC  -> No, connect to D36 (or to Gnd)
MCLK                                    Teensy D23
BCLK                                    Teensy D21
WCLK                                    Teensy D20
n_RESET_1                               You forgot this one!  This is critical!  Connect to D26!
GND                                     Teensy GND

I have not fully checked your other connections, but try making the changes above and let me know!

Chip

chipaudette commented 1 year ago

Below is an explanation of the two changes above, for anyone that cares...

Regarding the MIC_BIAS connection:

Regarding the n_RESET_1 pin:

Chip

zvikapika commented 1 year ago

Hi Chip,

Thank you so much for the detailed answers!

I have made the amendments you've described and I am happy to say that now I am not getting any error messages:

AudioPassThru: Starting setup()... Setup complete. Running... Running...

However, no audio is heard through the headphones connected to the shield. It was my understanding that the code is supposed to stream the input from the microphone connected to the shield, as is, to the headphones. Is that true? Can you advise what I can do to debug? Is there a sketch that checks the output and input separately?

Another question that might not be relevant, upon connecting the teensy to the computer it is recognized, per instructions on GIT, as a digital audio device. could it be that the audio i/o is transported through the computer instead of the earphones and microphones?

Thank you so much again, Zvika

On Wed, 12 Apr 2023 at 19:58, Chip Audette @.***> wrote:

Below is an explanation of the two changes above, for anyone that cares...

Regarding the MIC_BIAS connection:

  • This change is not critical. It is not the cause of your error messages. But, once you get the system working, this change will help your system's audio inputs work correctly.
  • The "MIC_BIAS" connection is an input to the AIC Shield, not an output from the shield. It is intended to be connected back to a GPIO pin on your microcontroller. The microcontroller sets it HIGH or LOW. If it is left floating ("NC"), I don't know what will happen.
  • The purpose of this line is to control whether mic bias is applied to the right input channel (IN_3_R). The AIC itself must be commanded (via software command) to generate the mic bias voltage. By default, though, the mic bias is only applied to the left channel (IN_2_R). To have the AIC mic bias voltage also be applied to the right channel (IN_3_R), you must pull the "MIC_BIAS" pin high. There is a command in the Tympan_Library to help with this.
  • If you never want mic bias, and you do not want to connect it back to the microcontroller, you can simply tie this pin to GND

Regarding the n_RESET_1 pin:

  • This change is critical. The AIC will never work without making this change.
  • The "n_RESET_1" pin is an input to the AIC Shield. It must be connected back to the microcontroller. It is used as part of the initialization and configuration process for the AIC (which is handled by the Tympan_Library)
  • The details of how this pin is used is too complicated to describe here. But, basically, the pin needs to be toggled by through various HIGH and LOW states during the initialization process. Without a connection to the microcontroller, these HIGH and LOW transitions never happen, which means that the AIC never initializes. As a result, the microcontroller cannot communicate with the AIC. The failure to receive any replies from the AIC is what causes the errors that you are seeing.
  • In short: you must connect this pin back to the Teensy

Chip

— Reply to this email directly, view it on GitHub https://github.com/Tympan/Tympan_Library/issues/67#issuecomment-1505776032, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAL63WT3WUYM7YHS7YLM5CDXA33O7ANCNFSM6AAAAAAW3QKGLQ . You are receiving this because you authored the thread.Message ID: @.***>

chipaudette commented 1 year ago

If you're not getting any errors, but you're also not getting any audio, lots could be wrong. I'd need to see a wiring diagram to help at this point:

Note that if you are using the pink jack, that's not what the Audio Pass Through example defaults to. It defaults to using the on-PCB microphones. There is an example line of code (commented out) that shows you how to switch to the pink jack (the microphone / line-in jack).

Chip

zvikapika commented 1 year ago

hi Chip, thanks again for the quick reply,

attaching the wiring scheme at the end of text, with a picture of the setup

we have tried using both amplified and non amplified stereo lapel microphone pair, connected to the shield via pink PL jack, and standard over-the-ear music headphones connected to the shield via black PL jack

if the audio input isn't strong enough, how would I know about it? I tried looking for sketches that test the microphone and the speaker separately, but could not find such.

By adding gain, you mean by software or hardware? I tried uploading the basicGain sketch, manually setting gain up to 0.95 (getting message on the serial monitor: servicePotentiometer: Digital Gain dB = 40.0) but still no audible sound was heard on the headphones

As for selecting the input source - you are right, I completely missed that. however I've tried the other two options, same result.

could it be that my earphones are the cause of the problem? Is there a way to test them separately?

Thanks again, Zvika

Shield Teensy 4.1

First row (from left) 1.8V Voltage regulated 1.8V (stepped down from on 5V of Teensy) IN1 RIGHT NC IN1 Left NC LINE OUT LEFT NC LINE OUT RIGHT NC GND GND

Second row MIC BIAS D36 MCLK D23 BCLK D21 WCLK D20 RESET D26 GND GND

Third row PDM CLK NC PDM DAT NC SDO NC SDI NC SCK NC CS NC

Fourth row 3.3V 3.3V DOUT D6 DIN D32 SDA2 D18 SCL2 D19 GND GND

image

biomurph commented 1 year ago

@zvikapika This is exciting! I will make a branch of the Tympan Rev E hardware git to modify the board to make this connection.

@chipaudette In 'normal' conditions, the AIC Shield is the secondary CODEC, but since this configuration doesn't have the main board CODEC, can the Teensy be connected with the primary pins? That would make this setup with the AIC Shield behave more like the Tympan E with no AIC Shield. Does that make sense?

zvikapika commented 1 year ago

I am now running the 'OutputTone' sketch, which, if I understood correctly, is supposed to test the headphones / sound generation only, but no sound is heard (I checked the headphones with another audio source and they are OK)

Maybe continuing your question, Is the connection of the AIC shield directly to the Teensy according to the above scheme supposed to work just like the Tympan Rev E (without bluetooth)?

Or, could it have to do with the teensy redirecting its audio to the USB due to its definition in the Teensyduino as a USB + MIDI + Audio device?

biomurph commented 1 year ago

@zvikapika This may be the issue that you are having. The library may be looking for the main-board CODEC. Try this: Use the main I2C bus

The other connections for MCLK, BCLK, WCLK are all correct. This way, the Tympan library with 'think' that it is talking to the main board AIC.

In the list of connections above, you have pins for SCL2 and SDA2 that are incorrect. Those are for the SCL and SDA. SCL2 is pin 24 and SDA2 is pin 25.

zvikapika commented 1 year ago

YES! YES! YES! YES! YES! I was missing the DIN and DOUT correct wiring, now I can get data from the mic and send to the earphones Thank you so much for your help! Upon finalizing the PCB, I can post the files in case that would be of any help Thanks again! Zvika

biomurph commented 1 year ago

awesome!

zvikapika commented 10 months ago

Hi all, happy so say the PCB works great, here is the gerber PCB design file https://www.dropbox.com/s/dvrs8dpdlbz85aw/final.rar?dl=1 Feel free to make it available on your site if you wish to

Thanks for all the help! another question, coming up :) Zvika

biomurph commented 10 months ago

@zvikapika Great news! I am unable to open the file you sent. Do you have your work on github?

zvikapika commented 10 months ago

Unfortunately not yet, in the process. But try this, should download as a friendlier format: https://www.dropbox.com/scl/fo/db8042lsb2tdci6rksucg/h?rlkey=z1zpo9n2cl09diqisckl4z6dy&dl=1 let me know whether it worked Zvika

biomurph commented 10 months ago

Yeah, that worked. I will have a chance to look at it in the next days.