Particle Agent breaks I2S functionality on Raspberry Pi Zero and 3

Hi
I’m using an I2S amplifier


for sound output which connects on
GPIO18, GPIO19 and GPIO21
Immediately the Particle Agent is installed the sound stops - no reboot required
I’ve tested on Raspberry Pi Zero and 3
Do you guys have a solution to either disabling Particle Agent from taking over pins? - or returning pins to OS control? - I suspect the later may be the route to immediate solution
Regards
Julian

Hi Julian,
We face the same problem with the Adafruit Speaker Bonnet. When one installs the Particle Agent also for this I2S device the music stops…

I have struggled trying to find an option to disable specific pins, but was unsuccesfull so far.

Edge

URL is by the way https://www.adafruit.com/product/3346

I would presume that stopping the particle-agent service would restore the I2S functionality?

Hi Kenneth

Good question - no it doesn’t

sudo particle-agent stop
speaker-test -c2

Silence

However if I

rm /var/lib/particle/devices/xxxxxxxxxxxxxxxxxxxxxxx/firmware.bin
sudo reboot
sudo particle-agent status

Shows service is running

speaker-test -c2

Sound working

What does this prove? - the Particle Agent is not part of this problem - the problem is entirely in the firmware image - in the initialization code - as soon as the firmware runs - it kills the I2S - stopping the firmware and the agent - doesn’t fix it - rebooting - and not running the firmware - but running the agent - “fixes” the problem

Also copying the firmware.bin file back immediately kills the I2S as the Particle Agent notices it’s back and immediately starts it up - robust!

Regards

Julian

If in setup you do the following:

void setup() {
 pinMode(A7, OUTPUT); //pin 40 on Rpi
 pinMode(D7, OUTPUT); //pin 35 on Rpi
 pinMode(A0, OUTPUT); //pin 12 on Rpi
}

can you check if it works? by first running the particle firmware and agent then start the speaker again.

Not sure if there’s a “lock” that only allows one process to access the GPIO pins but it might be worth just giving it a try :slight_smile:

I based the I2S connection pins on the schematic: https://learn.adafruit.com/assets/37882

Hi Kenneth and Edge

I’ve tried that - no go

However that is the right direction - I’ve found a workaround

Install WiringPi

sudo apt-get install git-core
cd ~
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build

then run these commands

gpio mode 1 alt0
gpio mode 24 alt0
gpio mode 29 alt0

and I2S functionality returns - the pins will be broken any time the firmware starts - either on boot - or on flashing - so these commands should be run in setup function

Regards

Julian

I hope the workaround is a good start. :slight_smile:

Eventually, it will be great to have this finer grain control in the firmware!

1 Like

You could make a script that runs these commands and call the script in your setup using Process Control.

https://docs.particle.io/reference/firmware/raspberry-pi/#process-control

Hi

I have streamlined this solution - as WiringPi is already in the Raspberry Pi firmware I’m able to call the function directly as below

extern "C" void pinModeAlt (int pin, int mode);
#define ALT0 0b100

void setup () {

  // Restore I2S pins

  pinModeAlt (GPIO18, ALT0);
  pinModeAlt (GPIO19, ALT0);
  pinModeAlt (GPIO21, ALT0);

Regards

Julian

2 Likes

Based on the discussion here, I’m planning on changing the behavior of the pin initialization on the Raspberry Pi. Thanks for the feedback!

2 Likes

Check Raspberry Pi: Pre-release firmware with improved pin initialization to try the new behavior.