Tic Stepper Motor Controller wit Adafruit Huzzah ESP8266

I went from the Arduino UNO platform to Adafruit Huzzah ESP8266. I need to control the stepper motor with Tic T834/T825 via I2C. Using Arduino UNO and Tic.h is OK. But I use Huzzah, I can only rotate the engine and I can not read the parameters from the TIC Controller.
Does anyone know how to edit the Tic.h library?

Hello.

I am sorry you are having trouble using the Tic with your Huzzah. You can find the Tic.h header file inside the Tic folder of your Arduino libraries. For example, on my Windows computer, the location of that folder is:

C:\Users\jon\Documents\Arduino\libraries\Tic

You can use a text editor to make changes to that header file. We are not very familiar with Adafruit’s Huzzah, so we do not have any particular recommendations on what modifications are necessary (if any) to get it to receive I²C data from the Tic. In general, the Tic library is intended to be portable and it does not have any AVR-specific code in it. If your programming environment has an Arduino-compatible implementation of the Wire library, then we expect that the Tic library should just work without any modifications.

-Jon

Hello Jonathan
Thank you for your quick reply. I use the IDE Arduino for programming. When Tic.hs did not work with my Huzzah library, I tried using the https://www.pololu.com/docs/0J71/all#10 “I2C Command Encodincg” to make a program using the Wira.h library, so I did not use the Tic library. But I do not know how to look.
I do not know what it is AVR-specific code.
Can you tell me what it looks like?
For example:

//master
#include <Wire.h>
int addr_for_write = 0x1C ; // slave add 14 + Wr
int command = 0xA1 ; // Get value
int offset = 0x0A ; // target position
long int = targetValue; // value from Tic

void setup(){
  Wire.begin();
  Serial.begin(9600);
}

void loop(){

  // write command
  Wrire.beginTransmission(....);
  Wire.write(...);
  ....
  ....
  Wire.endTransmission();


 //read value
  Wire.requestFrom(.....) ;
  while(Wire.available() > 0){
  ....... = Wire.read(); 
  .......
  targetValue = ??? // from Tic, ....... or more values
}

The Huzzah does not have hardware I²C pins, and I am not entirely sure if you can get things working by relying on the default pins that the Arduino Wire library would use in this case. So, instead of using Wire.begin(), you should call that function and pass through the GPIO pins you would like to use to perform software I²C (e.g. Wire.begin(5,6); // might work). After that, you can enter the device ID of the Tic, which is defaulted to 14, for Wire.beginTransmission(14). After making those changes, I recommend reading through Tic.h, starting at getTargetPosition(), to begin to figure out what else to add to your program.

Also, when you said you were able to rotate your stepper motor, was that accomplished by sending commands from your Huzzah through the Tic’s I²C interface?

-Jon

Yes, I rotate my stepper using the Tic.h commands via I2c. I just can not read the values as target positions. Wire.begin(5,6); thatI tried it. Maybe I’m doing it badly. Do not you write the whole code? Sorry for my English

correction
for Arduino and Huzzah is standard

Wire.begin(4,5); 

4(SDA) and 5(SCL), but that’s not the problem

Here is some minimal code that you can use that should basically be the same as getUpTime():

#include <Wire.h>
uint8_t address = 14;   // Default Tic I2C address
uint8_t command = 0xA1; // Get variable command
uint8_t offset = 0x35;  // Up time is 0x35, target position is 0x0A

void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  delay(1000);

  Wire.beginTransmission(address);
  Wire.write((uint8_t)command);
  Wire.write(offset);
  uint8_t error = Wire.endTransmission(false); // no stop (repeated start)

  if (error)
  {
    Serial.print("Error: ");
    Serial.print(error);
    Serial.println();
    return;
  }
  
  uint8_t byteCount = Wire.requestFrom(address, (uint8_t)4);
  if (byteCount != 4)
  {
    Serial.println("Error: wrong length read");
    return;
  }

  uint8_t buffer[4];
  for (uint8_t i = 0; i < 4; i++)
  {
    buffer[i] = Wire.read();
  }
  
  uint32_t position = ((uint32_t)buffer[0] << 0) |
    ((uint32_t)buffer[1] << 8) |
    ((uint32_t)buffer[2] << 16) |
    ((uint32_t)buffer[3] << 24);
  
  Serial.println(position);
}

Be sure to replace Wire.begin() with a version that passes the pins of the SDA and SCL lines that your Huzzah uses, like what you discovered: Wire.begin(4,5). Also update address if you changed the device number of your Tic.

We tested the code here on one of our A-Star 32U4 controllers and it worked. If it works for you, it should print a number each second, and each number should be about 1000 greater than the last.

-Jon

Hello Jonathan
Thanks for the program. I tried it, but it does not work. He writes the same number 4294967295. If I put the number on the buffer [0] … [3], he writes the number 255 (FF). Therefore, it can not read UP Time from Tis.
my Adafruit Feather HUZZAH with ESP8266, product 2821 works on logic 3.3V. I also downloaded 10kohm or 20kohm pull-up resistor to SDA, SCL.
I have two Tics T825 and T834 and the same way.
here are more information. To your email send my setting to Tic.

I do not understand :face_with_raised_eyebrow:

image

It sounds like there is something unique about the Huzzah that is preventing I²C communication using the Wire library. You might try contacting its manufacturer, Adafruit, to see if they have any specific recommendations.

-Jon

In other cases, Adafruit communicates with the slave via I2C. For example, display, temperature sensor and expander MCP23017 and others. It looks like I can not do it with Tic. Use a different controller of the stepper motor as a Tic, because I like it. Do you want to know what to do? Maybe I’m making a simple mistake. I have already gone through the Internet and I have not found any help. You’re probably my last hope. Please try to get in touch with your team.
Great thanks for your help.

I also have questions:

  1. Is it sure that Tic t834 works safely on 3.3V logic?
  2. Do not need “Logic Level Converter”?

Yes, the Tic’s I²C interface works with 3.3V logic signals. You can learn more about that under the “Setting up I²C control” section of the Tic’s user’s guide, which you can find under the Resources tab of its product page. So, you should not need a logic level shifter.

It is good to know that your Huzzah can communicate with other I²C devices. However, since you are able to get your Uno to work with your Tics, and you are able to send I2C commands to the Tics from your Huzzah, it still seems like the issue could be with how the Huzzah receives over its I²C interface.

If you have not already, you might double check that the devices in your system are sharing a common ground. Also, I suspect it might not affect things much, but you can try disabling the Tic’s built-in pull-ups on SCL and SDA, which is discussed in the section of the Tic’s user’s guide I referenced above. If things are still not working, you might try inspecting your signals with an oscilloscope or directly contacting Adafruit to see if they have any advice.

-Jon

Hello Jonathan
I read the user’s guide. I tried to connect i2c and other slaves at the same time as the hot sensor and OLED display. Everything is working O.K. The pull-up resistor in Tic must be disconnected because it would damage Huzzah. Tic is able to receive commands from the 3.3v but when sending data, they are always at HIGH for Huzzah. Logic 0 from Tic is always HIGH for Huzzah and it is logical 1. Huzzah reads FF (255).
I do not have an oscilloscope, so I can not verify it.
I also contacted Adafruit. They think it could help Logic Level Converter.
Maybe I will try. I do not have a better idea.

What kind of oscilloscope do you recommend from an amateur? I expect a connection with a PC at a good price.
well thank you

We do not have any specific recommendations for an oscilloscope.

Also, I do not really have much more advice for you, but if you post a picture of your setup that shows all of your connections, I can check to see if I notice anything obviously amiss.

-Jon

Hi, VladoH.

I tested an ESP8266 board with a Tic and was able to reproduce your problem. It looks like it’s caused by a bug in the ESP8266 Wire library (it doesn’t do a repeated start correctly when clock stretching is being done). You can work around the problem by editing this line in the sketch Jon provided above:

uint8_t error = Wire.endTransmission(false); // no stop (repeated start)

and removing false so that the Wire library does a stop and start instead of a repeated start:

uint8_t error = Wire.endTransmission();

Additionally, immediately after Wire.begin();, you might need to insert the line Wire.setClockStretchLimit(2000);, although you can start with the first change by itself to see if it works. Please let us know if these changes help.

Kevin

Hi, Kevin
It looks like it works. I will test it together with other slaves and then write.
well thank you.