Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2C Commands etc #2

Open
DaveDischord opened this issue Dec 27, 2018 · 5 comments
Open

I2C Commands etc #2

DaveDischord opened this issue Dec 27, 2018 · 5 comments

Comments

@DaveDischord
Copy link

Where can I find the i2c commands, address, etc?

@masutokw
Copy link
Owner

Speed 100k
Address 0x32

Commands
MOTOR_GET_COUNT 0x02

Send 0x02,
Read int32 (4 bytes)

MOTOR_SET_COUNT 0x03
Send 0x03 int32 (5bytes)

MOTOR_SET_TARGET 0x04
Send 0x04+ int32 (total 5bytes)

MOTOR_GET_TARGET 0x05
Send 0x05,
Read int32 (4 bytes)

MOTOR_SET_TICKS 0x06
Send 0x06+ int32 (total 5bytes)

MOTOR_SET_DIR_RES 0x7
Send 0x07+ int32 (total 5bytes)

@masutokw
Copy link
Owner

Speed timer frecuency 48khz
tick 20,8us
At this moment only min value -65535 to +65535
speed 65535-> 1,3s per microstep positive direction
speed 30000->0,65s per microstep positive direction
speed -15000->0,3125s per microstep negative direction

Resolution
1-> 32 msteps
2->16
4->8
8->4
counter is always 32 microsteps resolution
....

@DaveDischord
Copy link
Author

Thanks. I'm trying to write an Arduino library to implement into other codes. I'm sorry if I sound ignorant for asking, but what are the differences between ticks, target, and count. Like, what would the stepper do in sending MOTOR_SET_COUNT vs MOTOR_SET_TARGET vs MOTOR_SET_TICKS (plus 4bytes)? Also, with resolutions, are you to say that sendin MOTOR_SET_DIR_RES + [(uint32_t) value = 1] would set it to 32 msteps, [value = 2] = 16 msteps, etc?

@masutokw
Copy link
Owner

masutokw commented Dec 28, 2018

I have wrote some arduino code to check
I havent test it because a have my shield connected to my PC for developing and its bit tricky to dissasemble but compile for atmega328 and should work
This code initializes motor counter,move it to position 1000 at 32microsteps stops and return to home position at 16 microsteps resolution


#include <Wire.h>
#define SLAVE_ADDRESS_1 0x32
//Set Commands
#define MYSLAVE_SET_REG 0x01
//GET commands
#define MOTOR_GET_COUNT 0x02
#define MOTOR_SET_COUNT 0x03
#define MOTOR_SET_TARGET 0x04
#define MOTOR_GET_TARGET 0x05
#define MOTOR_SET_TICKS 0x06
#define MOTOR_SET_DIR_RES 0x7
void setup() {
 Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output

}

int32_t read_wms( uint8_t command, int address)
{ int32_t pos;
  char *pointer;
  char c;
 pointer=(char*)(&pos);

 Wire.beginTransmission(address); 
  Wire.write(command);             
  Wire.endTransmission();  
    
  delay(5);
  
   Wire.requestFrom(address, 4); 
    while (Wire.available()) { 
    char c = Wire.read();
    (*pointer++)=c;
    }
    return pos;
}

void write_wms( uint8_t command, int address,int32_t value)
{ 
  char *pointer;
  pointer=(char*)(&value);
 Wire.beginTransmission(address); 
  Wire.write( command);
  Wire.write(pointer,4);
  Wire.endTransmission();    

}
void loop() {

 //goto from 0 to 1000 
 int32_t pos=0;//set motor counter to 0
 int32_t target= 1000;//set desired position 1000
 int32_t speed=3000;//20,8 us * 300 =0.624s  ->16,02 microsteps/s 
 write_wms(MOTOR_SET_COUNT,SLAVE_ADDRESS_1,pos);//send counter
 write_wms(MOTOR_SET_TARGET,SLAVE_ADDRESS_1,target);//target set
 write_wms(MOTOR_SET_TICKS,SLAVE_ADDRESS_1,speed);//command speed
 while ( (pos=read_wms( MOTOR_GET_COUNT ,SLAVE_ADDRESS_1))!=target)
 {
  delay (100);
  Serial.println(pos);}

//motor will turn an stop until reach 1000 counter value

//now we command back 0 pos
  target= 0;//set desired position 0
 speed=-3000;//20,8 us * 300 =0.624s  ->-16,02 microsteps/s 
 int32_t resolution=2; //motor will no run on 16 msteps 
 write_wms(MOTOR_SET_DIR_RES,SLAVE_ADDRESS_1,resolution);
 write_wms(MOTOR_SET_TARGET,SLAVE_ADDRESS_1,target);//target set
 write_wms(MOTOR_SET_TICKS,SLAVE_ADDRESS_1,speed);//command speed
 while ( (pos=read_wms( MOTOR_GET_COUNT ,SLAVE_ADDRESS_1))!=target)
 {
  delay (100);
  Serial.println(pos);}
 

}
}

@masutokw
Copy link
Owner

masutokw commented Dec 28, 2018

I had compile anuploaded the skecth to mi wemos D1 and works fine with the shield
the arduino working code is at
[(https://github.com/masutokw/WEMOS-MOTOR-SHIELD-I2C-STEPPER/blob/master/arduino/)]
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants