Ir receiver and emitter

I’m working on grovepi with seeedstudio ir sensor, but have no any pyhton example code for them in grovepi lib.I also try using arduino irremote lib, but can not get them run :frowning:
Anyone has experiment with this, can show me a suggestion
Thanks

Hey,
The infrared receiver and transmitter are right not supported by the GrovePi though they are compatible with the GrovePi. Do let us know if you are interested in writing the code for IR sensor for the GrovePi. We’ll be happy to help you in any way possible.

-Karan

Hi karan
Thanks for reply.

I connected grove ir receiver sernsor to port D2 of grovepi, and in python script, call digitalread(2) to get value from sensor, but didn’t return anything.

To able to use this sensor, do i need modify firmware or anything setting?Can you know the reason

Hey,
To make the IR sensor work, you would have to update both the software and firmware.

You would have to update the software so that a command is sent to the GrovePi to start the receive function. In the firmware, you would have to add the receive functions from the Grove library: https://github.com/Seeed-Studio/IRSendRev/blob/master/IRSendRev.cpp . Then after receiving the command you would have to load the received data into the buffer and send it back to GrovePi library.

-Karan

Wow, that’s great.
I’m newbie to arduino also grovepi, very very happy if you can share your code or guideline to update firmware and software

Thanks for your support

Hey duyhb,
Let me get a tutorial up which should help you get started with making custom sensors with the GrovePi. It might take some time to get it up.

Untill then you can go ahead and do some reading on the GrovePi works here: http://www.dexterindustries.com/GrovePi/engineering/software-architecture/ and http://www.dexterindustries.com/GrovePi/engineering/grovepi-protocol-adding-custom-sensors/ .

-Karan

Hi Karan,

I have bought this sensor(emitter) too :
http://www.gotronic.fr/art-module-emetteur-ir-grove-wls12148p-18951.htm

I want use it for control the tv.

How to configure this one ?

We must connect it on Digital port or analog ?
And after what is the line for send Hz ?
Grovepi.analogWrite(sensor,xxx/Hz ?)
Grovepi.digitalWrite(sensor, xxx/xxxHz?)

Maybe i must to update the firmware? but this grovepi install was install just one month later maybe the command line for send frequency are already include.

Thanks for your help,
*Ps: Your firmware for multi-grovepi-installer is tested and approved with 4 grovepi and work succefull thanks :wink: !

Hey,
The IR emitter is not compatible right now to control the IR devices with the GrovePi. The emitter needs a big a complex library to be ported which you can find here:http://www.seeedstudio.com/wiki/Grove_-_Infrared_Emitter, we have not integrated it with the GrovePi yet. Let us know if you are interested in porting it but I suspect that it might be a big challenge.

-Karan

Hi Karan,

Thank you for your answer.

I wait for your software for use IR emitter !

When do you think that the software will be create ?

2nd question: This product can be supported by grovepi ? in analog port ? http://www.gotronic.fr/art-detecteur-de-mouvement-grove-sen32357p-18975.htm. ???

Hey,
We are working on the IR receiver software but we don’t have an ETA yet. You should keep checking regularly the supported sensors page to see if it completed.

The PIR sensor should work with GrovePi. The sensor gives digital HIGH or LOW signal to detect the presence one the potentiometer is set correctly. You can easily write logic to make it work with your program.

-Karan

Hey,

I have make IR transmitter working.
From iOS application, send command via MQTT to raspberry pi to remote tv.

Communication between grove pi+ and raspberry pi via I2C not stability, sometime I/O error occurred.
And when grove pi firmware raise error, must resetting firmware to fix it.
Do you know any way?

DuyHB

Hey,
In the IR transmitter project that you have working, is the IR transmitter connected directly to the Raspberry Pi or to the GrovePi.

The GrovePI sometimes throws errors which can easily caught using exceptions. If the GrovePi just goes down and does not stop throwing errors, can you upload the program here so that we can have a look at the output. Can you also paste what sudo i2cdetect -y 1 shows on the terminal once the GrovePi stops responding.

-Karan

Hi Karan
I have problem when send over 120 bytes from grove pi+ to raspberry.In raspberry’s python code can not receive all data.

Have any effective way to send and receive large byte data(over 120 bytes) between grove pi+ and raspberry pi?

Below is source code i’m working on.

1.Firmware
void loop()
{

if(cmd[0]==101) // IR decode
{
if (irRecv.decode(&results)) {
irSendFlg = 1;
updateIRReceive();
}
irRecv.resume();
}
}

void sendData()
{
if(cmd[0] == 101 && irSendFlg == 1){
int k = 1;
irSendFlg = 0;
if(irLen > 0)
{
irLen = irLen * 2 + 2;
irData[k++] = (byte)irLen;

     for (i = 0; i <= irLen; i++)
     {
        if( (k >= 32) || 
            (i == irLen)){
           Wire.write(irData, k);
           k = 2;
        }
        irData[k++] = (byte)irBuffer[i];
     }
     irLen = 0;
 }

}

void updateIRReceive()
{
codeType = results.decode_type;
irLen = results.rawlen;
if (codeType == UNKNOWN)
{
irLen–;

int val;
int k = 0;

// We need to convert from ticks to microseconds
for (int i = 1; i <= irLen; i++) 
{
  if (i % 2) 
  {
    val = results.rawbuf[i]*USECPERTICK - MARK_EXCESS;
  } 
  else 
  {
    val = results.rawbuf[i]*USECPERTICK + MARK_EXCESS;
  }
  irBuffer[k++] = val & 255;
  irBuffer[k++] = val >> 8;

}
}

  1. Python(grovepi.py)
    def irReceive_recv():
    write_i2c_block(address, irReceiveRecv_cmd +
    [unused, unused, unused])
    time.sleep(.3)
    try:
    data = []
    block = []
    #read_i2c_byte(address)
    data = read_i2c_block(address)
    if isinstance(data, list) and data[1] != 0
    and data[1] != 255:
    len = data[1] / 32

          if data[1] % 32 != 0:
            len = len + 1
       
      for b in data[2:]:
        block.append(b)
    
          time.sleep(.1)
      for i in range(len-1):
            data = read_i2c_block(address)
        	    
            for b in data[2:]:
          block.append(b)
          
        time.sleep(.05)
    
    return block
    

    except (TypeError, IndexError):
    print "irReceive_recv error"
    return -1

Thanks
DuyHB

Hi Karan
The IR transmitter connected directly to the GrovePi.
When error’s thrown, I tries running “sudo i2cdetect -y 1”, and it outputs 04
-> no problem

Rgds
DuyHB

Hey,
You cannot send more than 32 bytes of data at a time with I2C. What you can do is that break the data into blocks of 32 bytes and then send them one by one when you give the read_i2c_block command and decrypt the data on the raspberry Pi. You should checkout the implementation of the ultrasonic sensor for the GrovePi to see how we do it for 2 bytes and build on top of it.

-Karan

Hi Karan,

Above code I posted same as your solution,
The problem is in raspberry, can only receive the first block data (32 bytes).
You can refer to sample source i posted at May 18, 2015 at 4:44 am

for (i = 0; i <= irLen; i++)
{
if( (k >= 32) ||
(i == irLen)){ // send blocks of 32 bytes
Wire.write(irData, k);
k = 2;
}
irData[k++] = (byte)irBuffer[i];
}

Hey,
Sorry but I overlooked it, it is very hard to figure out what the code is doing exactly, is there a link to github or somewhere else where it would be easier to have a look.

Are you sure that with each read_i2c_block() call in Python, the data sent is at max 32 bytes. Is there any specific reason why you want to send that much data. It might be very hard to debug problems like this because I2C does not behave very well and usually needs a logic analyzer to make things work. I think using Serial might be easier to make it work, do you think it might work for you.

-Karan

Hi Karan, i just ask you about IR emitter Software,
When do you think that the Software will be ready ?
Thanks.

Hey,
The do you need the support for the IR emitter or the reciever. We have just added the support for the IR reciever in the last commit: https://github.com/DexterInd/GrovePi/tree/master/Firmware/Source/v1.2/grove_pi_v1_2_3 . It’s not available with the normal firmware update and you’ll have to upload the HEX file manually with avrdude -c gpio -p m328p -U flash:w:grove_pi_v1_2_3.cpp.hex.

Do let us know if you need the support for the emitter too.

-Karan

Hi Karan, I just update the firmware v1.2.3 HEX file manually.
But I meet a strange phenomenon: the LED modules could not be turned off if they are connect on the GrovePi+.It seem all ports were sending HIGH signal.And the IR receiver still could not get the data from remote neither.
Is there any procedure need to be performed after update the firmware? I have try to reboot the raspberry pi, but the problem still exist.
I recovered the firmware back to v1.2.2, the LEDs connected on the GrovePi+ all turned off.
And I want to compile the firmware by myself, could you pls help to provide some guideline?
Thanks a lot!