# LEDs on RIGHT PWM will not turn off completely and RPI Not Submitting Commands

**URL:** https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282
**Category:** Uncategorized
**Created:** [March 22, 2021, 6:56pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282 "2021-03-22T18:56:05Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![maraxen](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@maraxen](https://www.evolver.bio/u/maraxen)
#### Post date: [March 22, 2021, 6:56pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/1 "2021-03-22T18:56:05Z")

</div>

I am installing blue LEDs on our eVOLVER for optogenetic applications. To do this, I added a light variable to the conf.yml on the RPI and updated the Arduino handling a PWM in SA slot 8. I was able to get control from commands sent over the DPU; however, I am running into a problem someone described on here previously where the lights do not turn off with a zero sent.

Using the TLC test, I can turn off the entire RIGHT\_PWM which will blink the array of LEDs, but cannot get individual LEDs to turn off. There are still a few differences in the coding of how the left vs the right PWM are handled beyond the pin assignments. It seems like this may be something that could be resolved through the software libraries but I have extremely limited knowledge of Arduino.

I did testing Friday and I believe I turned off the eVOLVER while server\_test.py was going. After that, it started throwing errors and there seemed to be some difficulty in contacting the eVOLVER at the end of day. After returning today, I was not able to connect to the RPI through the electron shell or script. After trying to access by ssh it worked, and for whatever reason, conf.yml had the IP address noted as 192.168.1.27 instead of 192.168.1.2. Additionally, the formatting on the light variable was different. I updated the IP and connectivity to the DPU is restored, but I have not been able to get ANY commands working properly, whether scripted, sent through the desktop Electron GUI, or directly through the eVOLVER touchscreen.

I have attached the conf.yml in case there is something here. As you can see below, it is receiving the commands (I put some stir in at 15 and others at zero), but it is not acting on them. I reuploaded the relevant code for each Arduino to no avail.

```
acknowledge_char: a
broadcast_timing: 20
calibration: calibration.json
calibrations_directory: calibrations
data_response_char: b
device: evolver-config.json
echo_response_char: e
evolver_ip: 192.168.1.2
experimental_params:
  light: 
    fields_expected_incoming: 17 
    fields_expected_outgoing: 17
    recurring: false
    value: ['4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095']
  lxml:
    fields_expected_incoming: 17
    fields_expected_outgoing: 17
    recurring: false
    value: ['4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095', '4095']
  od_135: {fields_expected_incoming: 17, fields_expected_outgoing: 2, recurring: true,
    value: '1000'}
  od_90: {fields_expected_incoming: 17, fields_expected_outgoing: 2, recurring: true,
    value: '1000'}
  od_led:
    fields_expected_incoming: 17
    fields_expected_outgoing: 17
    recurring: true
    value: ['2500', '2500', '2500', '2500', '2500', '2500', '2500', '2500', '2500', '2500', '2500', '2500', '2500', '2500', '2500', '2500']
  pump:
    fields_expected_incoming: 49
    fields_expected_outgoing: 49
    recurring: false
    value: ['2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
      '2', '2', --, --, --, --, --, --, --, --, --, --, --, --, --, --, --, --, --,
      --, --, --, --, --, --, --, --, --, --, --, --, --, --, --]
  stir:
    fields_expected_incoming: 17
    fields_expected_outgoing: 17
    recurring: true
    value: ['15', '15', '15', '0', '15', '15', '15', '0', '15', '15', '15', '0', '0',
      '0', '0', '0']
  temp:
    fields_expected_incoming: 17
    fields_expected_outgoing: 17
    recurring: true
    value: ['2200', '2192', '2191', '2194', '2184', '2183', '2182', '2188', '2202',
      '2187', '2195', '2199', '2202', '2193', '2190', '2200']
fitted_data_directory: fittedCal
immediate_command_char: i
num_sleeves: 16
od_calibration_directory: od
port: 8081
raw_data_directory: rawCal
recurring_command_char: r
serial_baudrate: 9600
serial_end_incoming: end
serial_end_outgoing: _!
serial_port: /dev/ttyAMA0
serial_timeout: 0.3
temp_calibration_directory: temp

```

The server log is just an endless stream of “restarting supervisord”

---

<div class="post-metadata">

### Author: ![maraxen](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@maraxen](https://www.evolver.bio/u/maraxen)
#### Post date: [March 23, 2021, 3:04pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/2 "2021-03-23T15:04:23Z")

</div>

Update: some combination of moving light to be the last parameter and making the most recent updates on evolver\_server.py (courtesy of zheins) restored proper response and function!

So that problem is resolved, there is still the problem of the LEDs not turning off all the way. For our current purposes, it should be fine to just have some with/without LEDs, but we hope to do more complex optogenetic work in the future that having LEDs we can fully shut off will be necessary for

---

<div class="post-metadata">

### Author: ![bgwong](https://yyz1.discourse-cdn.com/flex035/user_avatar/www.evolver.bio/bgwong/32/262_2.png) [@bgwong](https://www.evolver.bio/u/bgwong)
#### Post date: [March 23, 2021, 10:35pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/3 "2021-03-23T22:35:39Z")

</div>

I thought this was solved by [this](https://github.com/FYNCH-BIO/evolver-arduino/issues/15) but I guess you are still have problems?

---

<div class="post-metadata">

### Author: ![maraxen](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@maraxen](https://www.evolver.bio/u/maraxen)
#### Post date: [March 24, 2021, 5:04pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/4 "2021-03-24T17:04:16Z")

</div>

I had raised a related issue with the pin assignments on [GitHub](https://github.com/FYNCH-BIO/evolver-arduino/pull/21#issuecomment-753218066). I have tried with both sets of pin assignments and the problem remains, although the registers I updated to seem to have the flickers sparser and more in sync. The other part that differs between the right and left in this part of the code is in the end TLC5490.h line 88, noted below, but I do not have good enough knowledge of Arduinos to know what the reasoning is behind the OR gate or if this could resolve the issue. I do know from my searches some aspects of certain PWMs make turning off all the way difficult or impossible.

```
//(LEFT_PWM DEFINES)

//Datasheet page 388
/** Enables the output of XLAT pulses */
#define enable_XLAT_pulses_1() PORT->Group[g_APinDescription[3].ulPort].PINCFG[g_APinDescription[3].ulPin].bit.PMUXEN = 1; PORT->Group[g_APinDescription[4].ulPort].PMUX[g_APinDescription[4].ulPin >> 1].reg = PORT_PMUX_PMUXO_F; REG_TCC1_CC1 = 1; while (TCC1->SYNCBUSY.bit.CC1)
/** Disables the output of XLAT pulses */
#define disable_XLAT_pulses_1() PORT->Group[g_APinDescription[3].ulPort].PINCFG[g_APinDescription[3].ulPin].bit.PMUXEN = 0; REG_TCC1_CC1 = 0; while (TCC1->SYNCBUSY.bit.CC1) 

//Datasheet page 388
/** Enable the GSCLK */
#define enable_GSCLK_1() PORT->Group[g_APinDescription[2].ulPort].PINCFG[g_APinDescription[2].ulPin].bit.PMUXEN = 1; PORT->Group[g_APinDescription[2].ulPort].PMUX[g_APinDescription[2].ulPin >> 1].reg = PORT_PMUX_PMUXE_F

//(RIGHT_PWM DEFINES)

//Datasheet page 388
/** Enables the output of XLAT pulses */
#define enable_XLAT_pulses_2() PORT->Group[g_APinDescription[8].ulPort].PINCFG[g_APinDescription[8].ulPin].bit.PMUXEN = 1; PORT->Group[g_APinDescription[8].ulPort].PMUX[g_APinDescription[8].ulPin >> 1].reg = PORT_PMUX_PMUXE_E; REG_TCC1_CC1 = 1; while (TCC1->SYNCBUSY.bit.CC1) //These are a problem
/** Disables the output of XLAT pulses */
#define disable_XLAT_pulses_2() PORT->Group[g_APinDescription[8].ulPort].PINCFG[g_APinDescription[8].ulPin].bit.PMUXEN = 0; REG_TCC1_CC1 = 0; while (TCC1->SYNCBUSY.bit.CC1) 

//Datasheet page 388
/** Enable the GSCLK */
#define enable_GSCLK_2() PORT->Group[g_APinDescription[7].ulPort].PINCFG[g_APinDescription[7].ulPin].bit.PMUXEN = 1; PORT->Group[g_APinDescription[6].ulPort].PMUX[g_APinDescription[6].ulPin >> 1].reg = !!!!PORT_PMUX_PMUXE_F | PORT_PMUX_PMUXO_F!!!!
```

---

<div class="post-metadata">

### Author: ![bgwong](https://yyz1.discourse-cdn.com/flex035/user_avatar/www.evolver.bio/bgwong/32/262_2.png) [@bgwong](https://www.evolver.bio/u/bgwong)
#### Post date: [March 24, 2021, 5:15pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/5 "2021-03-24T17:15:07Z")

</div>

@skumar Do you have any suggestions? Would really appreciate your advice here!

---

<div class="post-metadata">

### Author: ![skumar](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@skumar](https://www.evolver.bio/u/skumar)
#### Post date: [March 25, 2021, 11:12am UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/6 "2021-03-25T11:12:18Z")

</div>

This is strange. Have you tried just the RIGHT\_PWM (without initializing LEFT\_PWM) to see if that works on the right slot pwm board? That way you can be sure of which register assignments are correct for the RIGHT PWM.

If I remember correctly from my debugging experience on this, the register assignments are correct now…there was an issue while disabling XLAT pulses together (left and right pwms) which was then resolved with this [#17](https://github.com/FYNCH-BIO/evolver-arduino/pull/17)

---

<div class="post-metadata">

### Author: ![maraxen](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@maraxen](https://www.evolver.bio/u/maraxen)
#### Post date: [March 25, 2021, 4:15pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/7 "2021-03-25T16:15:24Z")

</div>

Perhaps I am misunderstanding what you are asking me to try or am completely misunderstanding the nature of the Arduino/SA slot setup; there is no LEFT\_PWM (unless that serves as a placeholder for the ADC board). In the code I have loaded to the Arduino handling the SA slots 7 and 8 which my LEDs are on, RIGHT\_PWM is called in Tlc.init and Tlc.set while LEFT\_PWM is not anywhere. While the dual PWM setup issues seem to be [resolved](https://www.evolver.bio/t/arduino-and-pwm-board-not-interacting-properly/205/2), was there testing on the main eVOLVER motherboard with an ADC board on the left slot and this on the right?

I also know that LEFT\_PWM will not work to control SA slot 8 because the TLC blink test I had done when originally installing only causes the LEDs to go on and off with RIGHT\_PWM.

As an aside, zheins comment in the linked forum post also has me confused as to the nature of daisy-chaining in this framework as my understanding was that each Arduino on the motherboard was controlling two SA slots that were daisy-chained in the code?

If worse comes to worse, I can probably swap the positions of the PWM and ADC boards and just crimp, wire, and solder to get the photodiode and LEDs into the appropriate holes, but obviously, a solution that resolves this issue more broadly is preferred.

---

<div class="post-metadata">

### Author: ![bgwong](https://yyz1.discourse-cdn.com/flex035/user_avatar/www.evolver.bio/bgwong/32/262_2.png) [@bgwong](https://www.evolver.bio/u/bgwong)
#### Post date: [March 25, 2021, 6:33pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/8 "2021-03-25T18:33:48Z")

</div>

The PWM boards on the Motherboard are not daisy chained. Slot 7 and slot 8 are controlled independently. For example, below you see that the Arduino D2 - 6 and A1 are going from the Arduino to one SA slot whereas D7 -11 and A0 are going to the other SA slot.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/evolver/original/1X/3f35e4b5b7f4fd30f4c3b9e2c4425f992d6a6aee.png)

The PWM boards in the fluidic box are daisy chained. You can see that the pins GSCLK, XLAT, and SCLK go from the Arduino to all the PWM boards. The commands are daisy chained by connecting the SOUT pin from the first PWM board (M1\_SOUT) to the SIN pin of the second board.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/evolver/original/1X/e9914ef0fac116bf661912f22d5a5d8e00f37109.png)

Generally, this was designed this way because if you need to control more than 32 channels, you would need more arduinos, if you didn’t daisy chain. By daisy chaining, you can potentially daisy chain a bunch more boards (up to ~100 channels I think), though we only stop at 3 PWM boards.

One last note, be careful with the notation LEFT\_PWM. LEFT would refer to slot 7 and RIGHT would refer to slot 8 in your case. It was named this way for legacy reasons but after the new enclosures they have become confusing.

---

<div class="post-metadata">

### Author: ![maraxen](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@maraxen](https://www.evolver.bio/u/maraxen)
#### Post date: [March 26, 2021, 4:34pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/9 "2021-03-26T16:34:27Z")

</div>

Thank you for the explanation and pin diagrams! And I have not run any LEFT\_PWM commands for this on the current vial platform thankfully. My understanding is better but I am more confounded by what could be producing the issue; I’ll think on this to try and come up with some careful troubleshooting and get back to y’all, the guidance is very much appreciated!

---

<div class="post-metadata">

### Author: ![maraxen](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@maraxen](https://www.evolver.bio/u/maraxen)
#### Post date: [April 6, 2021, 8:16pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/10 "2021-04-06T20:16:59Z")

</div>

Great news! I can control the blue LEDs through serial commands now, and there are no flickering issues! Big thanks to Brandon and skumar for their help throughout this process. I will link to a Notion detailing the installation/set-up process for our blue LEDs once I have compiled the necessary info.

After a week of exhaustive troubleshooting, the solution was frustratingly facile: Adding this code to the setup.

```
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);

  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);

```

Seems that in addition to Tlc.init, when you are running a RIGHT\_PWM off the eVOLVER motherboard, you also need to initialize the corresponding control pins in order to establish proper control.

You can find [the entire Arduino sketch here](https://github.com/maraxen/evolver-arduino/commit/be23a5e37f4355419da9807df5dbd4169148bbbb).

---

<div class="post-metadata">

### Author: ![bgwong](https://yyz1.discourse-cdn.com/flex035/user_avatar/www.evolver.bio/bgwong/32/262_2.png) [@bgwong](https://www.evolver.bio/u/bgwong)
#### Post date: [April 8, 2021, 12:13pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/11 "2021-04-08T12:13:17Z")

</div>

Glad it works! There is probably a modification in the library you can make to initialize properly via Tlc.init? Probably in this section of code. Did you happen to try that?

> <https://github.com/FYNCH-BIO/evolver-arduino/blob/885a526300e0a6bad58269a28709b7e5666b783d/libraries/Tlc5490_SAMD/Tlc5940.cpp#L167>

---

<div class="post-metadata">

### Author: ![maraxen](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@maraxen](https://www.evolver.bio/u/maraxen)
#### Post date: [April 9, 2021, 5:49pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/12 "2021-04-09T17:49:25Z")

</div>

I did not. I am pretty unfamiliar with coding in C++, but would the idea here be to make different logic gates for pwm\_val? To verify, RIGHT\_PWM gets converted to 2 through this line in Tlc5490.h?

> <https://github.com/FYNCH-BIO/evolver-arduino/blob/885a526300e0a6bad58269a28709b7e5666b783d/libraries/Tlc5490_SAMD/Tlc5940.h#L43>

If this understanding is correct, I would just need to have if statements for pwm\_val being one or two I believe?

---

<div class="post-metadata">

### Author: ![Nate\_Borders](https://yyz1.discourse-cdn.com/flex035/user_avatar/www.evolver.bio/nate_borders/32/268_2.png) [@Nate\_Borders](https://www.evolver.bio/u/Nate_Borders)
#### Post date: [April 11, 2025, 7:24pm UTC](https://www.evolver.bio/t/leds-on-right-pwm-will-not-turn-off-completely-and-rpi-not-submitting-commands/282/13 "2025-04-11T19:24:29Z")

</div>

This is an old thread, but I ran into this same issue when trying to use the RIGHT PWM. Thanks to this thread for giving me an easy hack if if not the ideal fix.

I made a pull request [here](https://github.com/FYNCH-BIO/evolver-arduino/pull/39) where I added Marielle’s code into Tlc5940.init() in the library so at least others will not run into this issue.

I (and chatGPT) did not see any issues in the code that might necessitate this. Attempts to do this a “clean” way using the following code failed:

```auto
if (pos_2) {
    // Make sure right pins are outputs and definitely driven LOW 
    SCLK_DDR_2 |= (1 << SCLK_PIN_2);
    SCLK_PORT_2 &= ~(1 << SCLK_PIN_2);

    SIN_DDR_2 |= (1 << SIN_PIN_2);
    SIN_PORT_2 &= ~(1 << SIN_PIN_2);

    XLAT_DDR_2 |= (1 << XLAT_PIN_2);
    XLAT_PORT_2 &= ~(1 << XLAT_PIN_2); // or HIGH, if that’s how left side does it

    BLANK_DDR_2 |= (1 << BLANK_PIN_2);
    BLANK_PORT_2 |= (1 << BLANK_PIN_2); // many designs start BLANK high
}

```
