Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Monster Mask question
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Monster Mask question

by pbuelow on Mon May 11, 2020 9:53 am

What would be the best way to have an RPi communicate with the Mask? I'm thinking i2c, but honestly, I have no idea how to do that, as both are masters on the bus. I know there are tutorials out there, so if i2c is the best way, I can probably figure that part out.

What I want to do is have an RPi running OpenCV for face detection, and then get 3 or 4 of the Masks mounted statically to stare where OpenCV sees a face. I think i2c is the best choice, but would be willing to hear other ideas. Or, if this has been done before and I just didn't search hard enough for a tutorial or example?

Also, the latest ArduinoJson does not like the comments in the config.eye files. I had to edit them out for this to work compiled against all of the latest libraries. Not a big deal, but I thought I would mention.

pbuelow
 
Posts: 58
Joined: Sat Oct 04, 2014 2:43 pm

Re: Monster Mask question

by mikeysklar on Mon May 11, 2020 2:41 pm

Hi pbuelow,

Interesting idea to lock on and stare at faces. This would be a fascinating installation.

You can use SPI, I2C or UART to communicate between your M4SK masks and the Pi. Since you are only sending minimal data between the masks and Pi (found face, coordinate positions for eyes) you could even using the GPIOs / PWM and analog pins.

Your question about getting started with I2C when both devices are masters can be resolved with running i2cslave on your masks.

https://circuitpython.readthedocs.io/en ... nit__.html

Personally my preference would be to keeping things clean and easy to debug so I'd create multiple software UARTS on the pi from GPIO pins or hardware UART expanders.

https://github.com/themrleon/RpiSoft-UART

Thank you for the feedback about the config file comments.

mikeysklar
 
Posts: 1743
Joined: Mon Aug 01, 2016 8:10 pm

Re: Monster Mask question

by pbuelow on Mon May 11, 2020 2:59 pm

Thank you. I didn't see a pins available for a UART. Right now, given that the i2c pins are available via a grove connector, I'm probably just going to do that. Thanks for the link for switching the roles, but it looks like I would need to run Circuit python for that. Since the Mask code is Arduino, can I do both? Otherwise, I found some instructions for using pigpio to become a slave which looks like it might work. Then I just have the mask ask for a location from the slave every repaint (or so) to know where to put the eyes.

pbuelow
 
Posts: 58
Joined: Sat Oct 04, 2014 2:43 pm

Re: Monster Mask question

by mikeysklar on Mon May 11, 2020 3:43 pm

pigpio looks like a great way to go on the Pi side for generating multiple UARTs.

here is some example code using the Wire.h library with Arduino for slave I2C should you go that route.

https://learn.adafruit.com/adafruit-see ... iting-data

mikeysklar
 
Posts: 1743
Joined: Mon Aug 01, 2016 8:10 pm

Re: Monster Mask question

by pbuelow on Mon May 11, 2020 3:59 pm

In hindsight, I don't think I'll be able to do i2c as this would be a multimaster solution (each pair of eyes is a single master, the PI is the slave) which isn't going to work with the pigpio solution as near as I can tell. Can I use the example you sent me with the where we switch I2C roles with the M4_Mask code Arduino code then? Otherwise, GPIO it may be!

pbuelow
 
Posts: 58
Joined: Sat Oct 04, 2014 2:43 pm

Re: Monster Mask question

by mikeysklar on Tue May 12, 2020 1:24 pm

Sure, you can use the M4 masks and i2c slaves on the arduino using the Wire.h library.

Here are the examples for reading and writing:

https://learn.adafruit.com/adafruit-see ... iting-data

Code: Select all | TOGGLE FULL SIZE
 void Adafruit_seesaw::read(uint8_t moduleBase, uint8_t moduleFunction, uint8_t *buf, uint8_t num, uint16_t delay)
{
  Wire.beginTransmission((uint8_t)_i2caddr);
  Wire.write((uint8_t)moduleBase); //module base register address
  Wire.write((uint8_t)moduleFunction); //module function register address
  Wire.endTransmission();

  delayMicroseconds(delay);

  Wire.requestFrom((uint8_t)_i2caddr, num);

  for(int i=0; i<num; i++){
    buf[i] = Wire.read();
  }
}


Code: Select all | TOGGLE FULL SIZE
 void Adafruit_seesaw::write(uint8_t moduleBase, uint8_t moduleFunction, uint8_t *buf, uint8_t num)
{
   Wire.beginTransmission((uint8_t)_i2caddr);
   Wire.write((uint8_t)moduleBase); //module base register address
   Wire.write((uint8_t)moduleFunction); //module function register address
   Wire.write((uint8_t *)buf, num); //data bytes
   Wire.endTransmission();
}


pigpio should work as well if you were to run it on your Pi and create 4 seperate UARTS one for each mask.

mikeysklar
 
Posts: 1743
Joined: Mon Aug 01, 2016 8:10 pm

Re: Monster Mask question

by pbuelow on Tue May 12, 2020 2:45 pm

Hmm, cool. If I do the slave you have below, then how do I know it's time to read? Is this just a loop and check for an available message, or is it possible to fire a callback? Interrupting the display for a few ms isn't the end of the world.

I will prototype the pigpio to UART code if you tell me where to connect to a UART on the Mask (the pinout page doesn't list a UART available externally). I've got some initial coding done to be the protocol and sending a face location to listeners, so whenever I can figure out how to connect to the device, I can try something out.

pbuelow
 
Posts: 58
Joined: Sat Oct 04, 2014 2:43 pm

Re: Monster Mask question

by mikeysklar on Tue May 12, 2020 3:02 pm

I would start with a loop check based on a millis counter initially just to test out your concept. The interrupts combined with i2c slave code might be a lot to take on at once.

I attached an image from the monster mask primary guide about where you could setup a SERCOM UART on the JST SH port on the bottom of the mask.

https://learn.adafruit.com/adafruit-mon ... es/pinouts

At the bottom on the right side is a 4 pin JST SH port for connecting an optional PDM microphone. Note that the PDM microphone is connected to two SERCOM pins, and we use SPI2 to read PDM data (if you think about it, PDM is just fixed-frequency SPI!) You could in theory turn this into an I2C or UART port. The SAMD51G19 chip used on this board does not support I2S, so we can't use I2S to read the PDM data.


B92790FD-3158-47A0-824E-6F25A260BDE4.png
B92790FD-3158-47A0-824E-6F25A260BDE4.png (496.12 KiB) Viewed 68 times

mikeysklar
 
Posts: 1743
Joined: Mon Aug 01, 2016 8:10 pm

Re: Monster Mask question

by pbuelow on Tue May 12, 2020 4:01 pm

Thank you, I don't have that connector at home, but will work on it, but that's pry the best choice. Next couple of months will be hacking up some solutions, and I'll post updates as I get there. We just got word that the event I was going to show this at will be significantly different this year for distancing reasons, so it may end up being a 2021 display instead.

Thank you very much for all of your help.

pbuelow
 
Posts: 58
Joined: Sat Oct 04, 2014 2:43 pm

Please be positive and constructive with your questions and comments.