Go Down

Topic: Arduino Nano I2C controlling Energenie Pi-Mote for Raspberry Pi  (Read 1 time) previous topic - next topic

0597d21

Hello All,

I am new to this forum so hopefully I am posting at the right place.

I am trying to control remotely control sockets from Pi-Mote using Arduino Nano over the I2C using chip MCP23017. How the Pi mote works is on this link Pi mote & Python.

Before I have managed to control the Pi mote using just the pins on the Arduino UNO using this code Arduino Pimote . It worked with no problem. But when I came to the point trying to expand it using the Arduino Nano and the chip MPC23017 it doesn't work.

Thank you for help..

Code: [Select]

#include <Wire.h>

// Codes for switching on and off the sockets
// Socket: all      1       2        3       4
//  ON = ['1011', '1111', '1110', '1101', '1100']
// OFF = ['0011', '0111', '0110', '0101', '0100']


// ----------------
//    Functions
// ----------------

/*
 */

void setupMPC23017()
{
  char* sides[]={"A", "B"};
  
  int chipSide[] = {0x00, 0x01}; // [IODIRA, IODIRB] register
  int chipSides = 2;
  
  for (int i=0; i < chipSides; i++)
  {
    Wire.beginTransmission(0x20);
    Wire.write(chipSide[i]); // register
    Wire.write(0x00); // set all of port as outputs
    Wire.endTransmission();
    outputMPC23017(sides[i], 0);
  }
}


void clearOutputSettings()
{
  char* side[]={"A", "B"};
  int chipSides = 2;
  
  for (int i=0; i < chipSides; i++)
  {
    outputMPC23017(side[i], 0);
  }
}

/*
 */

void outputMPC23017(String chipSide, int output)
{
  Wire.beginTransmission(0x20);
  
  // address port A
  if(chipSide == "A")
    Wire.write(0x12);
  
  // address port B
  if(chipSide == "B")
    Wire.write(0x13);
    
  Wire.write(output);  // value to send
  Wire.endTransmission();
}

/*
 */
 
void manageOutput(String chipSide, int output[])
{
  // sending code to activate or deactivate socket
  outputMPC23017(chipSide, output[0]);
  // let it settle, encoder requires this
  delay(100);
  // Enable the modulator
  outputMPC23017(chipSide, output[1]);
  // keep enabled for a period
  delay(250);
  // Disable the modulator
  outputMPC23017(chipSide, output[0]);
}

/*
 */
 
void switch_on(int socket, String chipSide)
{
  if(socket == 0)
  {
    int output[] = {11, 27};
    manageOutput(chipSide, output);
  }
  else if(socket == 1)
  {  
    int output[] = {15, 31};
    manageOutput(chipSide, output);
  }
  else if(socket == 2)
  {
    int output[] = {14, 30};
    manageOutput(chipSide, output);
  }
  else
  {
    int output[] = {0, 0};
    manageOutput(chipSide, output);
  }
}

/*
 */

void switch_off(int socket, String chipSide)
{
  if(socket == 0)
  {  
    int output[] = {3, 19};
    manageOutput(chipSide, output);
  }
  else if(socket == 1)
  {
    int output[] = {7, 23};
    manageOutput(chipSide, output);
  }
  else if(socket == 2)
  {
    int output[] = {6, 22};
    manageOutput(chipSide, output);
  }
  else
  {
    int output[] = {0, 0};
    manageOutput(chipSide, output);
  }
}

/*
 *    Begin  
 */

void setup() {

  Serial.begin(9600); // Serial Communication
  Wire.begin();       // wake up I2C bus
  setupMPC23017();    // wake up MPC23017
}


void loop() {
  switch_on(2, "B");
  clearOutputSettings();
  delay(1000);
  switch_off(2, "B");
  clearOutputSettings();
  delay(1000);
}


pylon

Don't you think a schematics of your setup might support us to help you?

The two pages you linked to don't use the MCP23017, so you must have your own setup and we should know how that looks like.

Did you try if the MCP23017 does what you expect it to do with having the Pi-Mote connected? You don't check the result code of Wire.endTransmission() so you don't know if the chip acknowledges your commands or not.

0597d21

Sorry I am completely new, here is the schema where I have used the MCP23017. I have tested the circuit event with the pull down resistors of 10K each on the output but these are not on the image.

The pimote sits on the cobbler header.



I have used the LED's to visually test the bits which are required to switch on or off the pi mote. The pages I have linked do not use the MPC23017 chip. I have linked these to give a bit of info on the Pi-mote from Energenie.

The reason I am trying to incorporate the MPC23017 Chip is to free up the pins on nano because one pimote requires 6 pins to run. Other thing is it looks to me, all you need to run the pimote is to send predefined bits to the device and it should work so I must be missing on something.

One last thing on my mind is I have not seen it done by anyone to have the chip used to drive the pimote. So I was thinking maybe it can be done.

Thank you for help...  

pylon

If you don't connect the Pi-Mote, can you see the corresponding patterns on the LEDs?

Did you check if the Pi-Mote pins are 5V compatible (the Pi is running on 3V3)?

0597d21

Luckily the Pi mote can handle 5V output, I have done the test using Arduino Uno and I was able to interact with the remotely controlled sockets. I do see the expected led light up as they should to translate the command to interact when the pimote is not connected.

I have got a hypothesis but I am not sure, I think when I am sending the 4 bit value between D0-D3 from  Raspberry Pi or the Arduino pins the 4 bit value is transmitted in the sequence to the Pi-mote. But with the MPC23017 chip it throws the 4 bits value at one time which might cause the issue. What do you think?

pylon

According to the schematics bit 4 of port B of the MCP23017 is connected to GPIO24 of the Pi connector and is MODSEL. In your code you're enabling that for the CE signal, but that signal is on GPIO25 of the Pi connector. Swap the connections of bit 4 and bit 5 of port B and try again.

0597d21

yeah true, did not spot this. It works now thank you very much

Go Up