Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 3.2 and ESP8266 communications

  1. #1

    Teensy 3.2 and ESP8266 communications

    Hello,

    I have a Teensy 3.2 that controls a DM320 motor driver. It also receives interrupt information from optical switches when the linear actuator that is controlled by the DM320 reaches physical actuator endpoints. This all works well and Teensy is ideally suited for this type of application. Now I need to control this by WiFi and for that I've used an ESP8266. The big issue is to separate the motor control and the WiFi to reduce instability. So now to communicate between the 2 micro-controllers I was planning on using the serial port - i.e. send "320 steps up" or "320 steps down" from the ESP8266 to the Teensy, and then have the Teensy send back the number of steps it could complete. I've done this before and it seems to work OK, but I was wondering if there might be a more efficient or easier way to do this. Previously, I would send a command from one controller to another via the serial port, and then raise an interrupt to notify the other controller that a message was waiting. Any other ideas or comments?

  2. #2
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    86
    I would do this via i2c. Teensy as slave and define my own "protocol" to do that.

    Here is a thread about i2c: https://forum.pjrc.com/threads/35500...cation-problem

  3. #3
    Quote Originally Posted by mstiller View Post
    I would do this via i2c. Teensy as slave and define my own "protocol" to do that.

    Here is a thread about i2c: https://forum.pjrc.com/threads/35500...cation-problem
    I think you are right - I was thinking about doing that as well. Would definitely save some connections since I already have a I2C OLED to display the IP Address. So in this case I would have the ESP8266 as the master and
    the Teensy and OLED as slave devices. This might work since I would rarely change the OLED display once the IP address was known.

  4. #4
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    86
    Another possibility - as i am a big fan of that Adafruit Feather system - is to use their airlift feather wing and their teensy feather adapter.
    This would then use SPI to communicate between them, and it would be an ESP32 basically.

    But i did not try this and it would require to buy more hardware.

  5. #5
    Quote Originally Posted by mstiller View Post
    Another possibility - as i am a big fan of that Adafruit Feather system - is to use their airlift feather wing and their teensy feather adapter.
    This would then use SPI to communicate between them, and it would be an ESP32 basically.

    But i did not try this and it would require to buy more hardware.
    Wow - now that is a nice way to do this - thanks for telling me about it!
    I found ESP8266 was, oddly, more refined than the ESP32 especially in the SoftAP mode. However ESP8266 runs out of IO and I had to constantly tend the watchdog timer as long periods of motor control
    would upset the processor. Bring on the Teensy 3.2 which is a much better choice for motor control.

  6. #6
    So I have a question that might help others as well. I have my master (ESP8266) which essentially receives liner actuator movement request via WiFi and then must tell the Teensy 3.2 (basically in the role of motor controller) what direction and how many steps
    to take in that direction. I understand the master - > slave relationship. Basically I can set up the Teensy as shown below and receive data from the ESP8266...

    Code:
    Wire.begin(I2C_SLAVE, TEENSY_I2C_ADDRESS, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);
    Wire.onRequest(receiveEvent);
    .
    .
    void receiveEvent(size_t len)
    {
    	dbLen = len;
    	Wire.read(databuf, len);  
            // do something with the data from the 8266...
    }
    Now I know I can also set up a receiveEvent callback in the slave where it will send data back to the master when the master requests this. But in this case, the time the Teensy (slave) spends moving the
    actuator is unknown and varies considerable from call to call. So one time it might spend 20 millis on a movement while other time it may spend 15 seconds. And that is the point of my question - can the slave
    indiscriminately send data back to the master without the master requesting this? In this scenario the motor controller might meet the upper or lower bounds of the actuator and move only enough to trip the
    limit switch. To ensure the user program does not get out of sync, the Teensy motor controller (slave) need to send how many steps was actually taken back to the ESP8266 (which might be less than the number requested
    if it hits the limit switches). As you could see, the master would have no way of knowing when the slave was done and therefore would have to poll the slave until the operation was done - sounds inefficient to
    me.

    I was hoping I could setup something like that shown below in the slave and have then send it to the master when the motor movement is finished...

    Code:
    void DoMotorControlReply()
    {
    	char szDebug[100] = { 0 };
    	bProcessReplyCommand = false;
    	memset(databuf, 0, MEM_LEN);
    #ifdef DEBUG
    	sprintf(szDebug, "The return code is %u and the steps are %u", mc.uiCode, mc.uiSteps);
    #endif // DEBUG
    	_DebugPrintln(szDebug);
    	sprintf(databuf, "%s#%s|", mc.uiCode, mc.uiStepsTaken);
    	Wire.write(databuf, MEM_LEN); // fill Tx buffer (send full mem)
    
    }
    So is this possible - or do I need to poll from the master if the operation has completed? Am I overthinking this one - i.e. when the master requests data from the slave, can there be a large delay before the slave sends data?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •