Masters, Slaves and Failures

August 18th, 2015 3 min read

Series

This post is part of the Automatic Curtains series. Check out the other posts here:

    Tags

    Ads via Carbon

    After I finally finished the first test motor unit I ordered all the necessary parts on eBay to built the 4 final units. Since most of the parts will take a while to arrive, I decided to work on the control unit testcase. Since eBay isn’t world’s fasted way to acquire parts, I have a lot of time to work on this … So let’s get going!

    image

    The full setup of my curtain system will consist of 4 motor units, and 1 control unit. This control unit will communicate with the motor units using I2C and will eventually contain a wifi module for internet connectivity. But, for the time being, it will consist of a simple OLED screen and a rotary encoder.

    image

    With these basic parts in place, I decided to do some communication testing between 2 Arduino’s using the I2C protocol.

    Although there a lot of promising upcoming communication protocols like the recently released PJON, I chose to use I2C because it’s a proven protocol. It besides a shared ground it uses 2 wires to communicate: one clock line, and one data line.

    As Wikipedia states:

    I²C (Inter-Integrated Circuit), pronounced I-squared-C, is a multi-master, multi-slave, single-ended, serial computer bus invented by Philips Semiconductor (now NXP Semiconductors). It is typically used for attaching lower-speed peripheral ICs to processors and microcontrollers.

    In my case, I decided to use my controller as the Master, and the 4 motor units as slaves. Essentially, this is a legal way to have 4 slaves in my household …

    image

    Luckily, the Arduino website has some perfect documentation about using I2C as a communication protocol. So within a few minutes I got my Arduino to Arduino communication up and running.

    To summarize the most important lines of code for my setup:

    Controller:

    void setup() {
        Wire.begin();       // join i2c bus as master
    }
    
    void loop() {
        // somewhere in loop, ie. after a button press ...
        Wire.beginTransmission(1);      // transmit to motor unit 1
        Wire.write(targetValue);        // sends one byte (0-255) to the motorUnit
        Wire.endTransmission();
    }
    

    Motor Unit:

    void setup() {
        Wire.begin(1);  // join i2c bus with address #1
        Wire.onReceive(receiveEvent);
    }
    
    void receiveEvent(int howMany) {
        int curtainTarget = Wire.read();    // receive the new target
    }
    

    So, with this up and running, it’s time to combine the test controller and the I2C communication … And that’s where I ran into a wall! Apparently, the OLED screen (which also works on the I2C bus), doesn’t want me to connect some extra wires to the Clock and Data lines. As soon as I do, the screen goes blank, and the Arduino stops working. Even without anything connected to that wire.

    Yeah, seriously … So I hope my eBay sellers take some extra time, cause I first need to solve this mystery … Any hints are welcome.

    Edit 2015/08/19: As commenter Kuba states, the I2C bus can’t be as long as I need them to be. Since I need at least 7 meters of cable, I2C isn’t an option … Back to the drawing board … More info about this issue can be found here.

    Loading comments …
    ©2021 - MichaelTeeuw.nl