I’ve been working on an esphome custom firmware for the toniebox and I’ve made a custom component for the dac3100 that is used in the toniebox (I will later be working on a custom component for the rfid tag reader and the accelerometer). So far everything works (ear buttons, deep sleep, wake up, led, charge voltages) but for some reason the audio dac is unresponsive on the i2c bus. I can even see the accelerometer show up on the i2c scan (address 0x19) but no response from the audio dac.
I know there was a project with the revvox team to make custom firmware for the toniebox. Was the dac ever functional with that firmware? is there something I’m missing in the setup process to make the dac responsive on the i2c bus? I’ve looked through Texas Instruments documentation for the dac and can’t find anything that I’m missing. The toniebox I’m testing on did have a tinny speaker (I replaced the speaker itself to fix that but haven’t been able to test it since) but I’d be surprised if that caused the i2c interface to the dac to become unresponsive.
Here is the esphome yaml file
esphome:
name: toniebox
friendly_name: TonieBox
on_boot:
priority: 1200
then:
- lambda: |-
gpio_set_direction(GPIO_NUM_26, GPIO_MODE_OUTPUT);
gpio_set_level(GPIO_NUM_26, 0);
vTaskDelay(10/portTICK_PERIOD_MS);
gpio_set_direction(GPIO_NUM_45, GPIO_MODE_OUTPUT);
gpio_set_level(GPIO_NUM_45, 1);
vTaskDelay(10/portTICK_PERIOD_MS);
gpio_set_level(GPIO_NUM_26, 1);
vTaskDelay(10/portTICK_PERIOD_MS);
preferences:
flash_write_interval: never
esp32:
board: adafruit_feather_esp32s3_nopsram
flash_size: 8MB
variant: ESP32S3
framework:
type: esp-idf
external_components:
- source:
type: git
url: https://github.com/binvention/esphome
ref: tlv320dac3100
components: [dac3100]
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "key"
ota:
- platform: esphome
password: "pass"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
reboot_timeout: 0s
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Toniebox Fallback Hotspot"
password: "pass"
captive_portal:
deep_sleep:
id: deep_sleep_1
run_duration:
default: 10min
wakeup_pin:
number: GPIO7
inverted: true
mode:
input: true
allow_other_uses: true
#dac and accellerometer bus accellerometer irq is gpio14
i2c:
- sda: GPIO5
scl: GPIO6
scan: true
id: i2c_bus_1
frequency: 400khz
audio_dac:
- platform: dac3100
id: main_dac
i2s_audio:
- i2s_lrclk_pin: GPIO12
i2s_bclk_pin: GPIO11
speaker:
- platform: i2s_audio
dac_type: external
i2s_dout_pin: GPIO10
id: main_speaker
channel: left
audio_dac: main_dac
- platform: mixer
output_speaker: main_speaker
source_speakers:
- id: announce_speaker
- id: media_speaker
media_player:
- platform: speaker
announcement_pipeline:
speaker: announce_speaker
format: WAV
media_pipeline:
speaker: media_speaker
format: WAV
name: "TonieBoxSpeaker"
codec_support_enabled: false
#rfid bus CS is GPIO1 IRQ is gpio 13
spi:
- id: spi_bus0
clk_pin: GPIO4
mosi_pin: GPIO2
miso_pin: GPIO3
interface: hardware
#battery sensor
sensor:
- platform: adc
pin: GPIO8
name: "Charge Voltage"
update_interval: 60s
filters:
- multiply: 2
- platform: adc
pin: GPIO9
name: "Battery Voltage"
update_interval: 60s
filters:
- multiply: 4
output:
- platform: ledc
pin: GPIO17
id: blueled
channel: 0
- platform: ledc
pin: GPIO18
id: greenled
channel: 2
- platform: ledc
pin: GPIO19
id: redled
channel: 4
switch:
- platform: gpio
pin: GPIO45
id: dac_power
restore_mode: ALWAYS_ON
- platform: gpio
pin:
number: GPIO26
ignore_pin_validation_error: true
id: dac_reset
restore_mode: ALWAYS_ON
light:
- platform: rgb
red: redled
blue: blueled
green: greenled
name: "Indicator Light"
binary_sensor:
- platform: gpio
pin:
number: GPIO20
inverted: True
mode:
input: True
name: "Big Ear"
- platform: gpio
pin:
number: GPIO21
inverted: True
mode:
input: True
name: "Small Ear"
- platform: gpio
pin:
number: GPIO7
inverted: True
mode:
input: True
allow_other_uses: true
name: "Wake Up"
on_press:
then:
- deep_sleep.prevent: deep_sleep_1
on_release:
then:
- deep_sleep.allow: deep_sleep_1
And the log from esphome
[07:56:13][C][i2c.idf:079]: I2C Bus:
[07:56:13][C][i2c.idf:080]: SDA Pin: GPIO5
[07:56:13][C][i2c.idf:081]: SCL Pin: GPIO6
[07:56:13][C][i2c.idf:082]: Frequency: 400000 Hz
[07:56:13][C][i2c.idf:088]: Recovery: bus successfully recovered
[07:56:13][I][i2c.idf:098]: Results from i2c bus scan:
[07:56:13][I][i2c.idf:104]: Found i2c device at address 0x19
[07:56:13][C][dac3100:068]: DAC3100:
[07:56:13][C][dac3100:069]: Address: 0x30
[07:56:13][E][dac3100:072]: Communication with DAC3100 failed
[07:56:13][E][component:082]: Component dac3100.audio_dac is marked FAILED
For clarification the lambda function on boot in the esphome yaml is to turn on the dac (and apparently also the i2c power since without it it says that sda is suck low). Following the recommendation in texas instruments documentation I first pulled the dac reset low then the power high then the reset high. Needs to be done in the lambda because otherwise its not ready in time for the esphome i2c library to work. If anyone has an idea as to what the problem could be I’d appreciate the input
---- Update ----
By removing the attempt at resetting the dac and just driving the reset signal high I get it to respond. I can now get audio out but it sounds bad. barely recognizable so I need to mess with the audio settings programmed into it.