I want to have a some leds change color as the direction and pitch

(Alan Johnstone) #1

I want to have a some leds change color as the direction and pitch changes.
I have wired up an old CMPS10 - Tilt Compensated Compass Module that I have using the following code. It works perfectly on an Arduino UNO but when I move the sketch to an Arduino DUE it stops immediately I provide power to the leds.Up to that point the compass is happily spewing out data. The thing hangs up so badly that It will not reboot without turning off the power to the DUE ( and turning off the Lights)

I am using Fastled 3.20, the IDE is running on Windows 10 and I am using genuine Arduino UNO and DUE. The lights are WS2812B 300 led/m

I have previously run the leds on the DUE using several of the example sketches with no problems.

The CMPS10 is controlled using I2C and I am pretty certain that it is this that is hanging but I do not know why.

I have also tried having the power to the leds on before providing power to the DUE but that does not help.two Arduinos is that the I2c pins are A4 and A5 on the Uno and 20 and 21 od the DUE

The only difference in the wiring of the

#include <Wire.h>
#include “FastLED.h”
#define NUM_LEDS 150
#define DATA_PIN 6

#define ADDRESS 0x60 // Defines address of CMPS10

void setup()
Wire.begin(); // Conects I2C

void loop(){

char pitch; // Stores pitch char used because they support signed value
byte val;
int intPitch;

Wire.beginTransmission(ADDRESS); //starts communication with CMPS10
Wire.write(1); //Sends the register we wish to start reading from

Wire.requestFrom(ADDRESS, 4); // Request 4 bytes from CMPS10

while(Wire.available() < 4); // Wait for bytes to become available

val = Wire.read();
pitch = Wire.read();

Serial.print("Val ");Serial.print(val);

intPitch = pitch;
Serial.print(" Pitch “); Serial.println(intPitch);
//Serial.print(” Roll ");Serial.println(roll);
FastLED.showColor(CHSV(val, 200,200));

(Alan Johnstone) #2

The last sentence should say

The only difference in the wiring of the two Arduinos is that the I2c pins are A4 and A5 on the Uno and 20 and 21 on the DUE

(Jeremy Spencer) #3

Try a big capacitor across the led power supply, and another one across the power to the compass, also are the grounds connected?

(Alan Johnstone) #4

@Jeremy_Spencer Thank you for your suggestion. I added a further 680uF to the led strip which already has 100uF and added a 680uF to the compass power. They are the biggest capacitors I have on hand. It did not work!

I have now tried reading the Compass using serial comms which is another option. That has worked. That almost certainly confirms that it is the I2C comms that is being affected. I have had these kind of problems with I2C before when reading my LIDAR Lite 2 . Its comms were very flakey and the blurb for the LIDAR Lite 3 says that they have improved them. Maybe the latest CMPS12 has also been improved, but I have never previously had any problems with this compass which has previously been attached to an Arduino UNO, Mega and an RPI2. So maybe it is the Arduino DUE part of the comms that is affected. So anyway as I have a work around I will move on. I have now got to get reading an SD card working so as to provide sound as well as light which was the reason for moving to the DUE in the first place.

(Mark Estes) #5

due is 3.3 volt i/o, adruino is 5 v i/o. strips like 5 volt signal. that could be why the strip is unhappy on due. consider shift register

(Jeremy Spencer) #6

The other thing to try is this

before you #include <FastLED.h>. Sometimes, especially on the esp8266, you might have better luck by just tweaking the re-try attempt code with:

before you #include <FastLED.h>

from here https://github.com/FastLED/FastLED/wiki/Interrupt-problems