Close
0%
0%

WEMOS Motor Shield firmware for steppers (I2C)

Use your Wemos motor shield with steppers motors I2C custom slave interface

Similar projects worth following
A new application for cheap WEMOS Shield Motor DC driver From full step to 32 microsteps voltage sinoidal microstepping.Editable microstep table ,Many steppers as I2C addresses free in your app.Commands speed, target and resolution.Arduino skecth example, working on ESP82266 and AVR micros..Beta but functional .Includes windows example for FT260 i2c Dongle.Source code and Firmware availalble on Github.

I2C code  based on interrupts , no polling code.

I2C Clock Speed 100Khz

Address 0x32 (editable at HEX file)  

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 0x07: Send 0x07+ int32 (total 5bytes)

 MOTOR_SET_PRESCALER 0x08:Send 0x08+ int32 (total 5bytes)

MOTOR_SET_WAVE_SCALE 0x09:Send 0x08+ int32 (total 5bytes)

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

Arduino test code (works on AVR and esp8266)

#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 1000
 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);}
 

}

tb6621.hex

Updated firmware

hex - 17.66 kB - 01/18/2019 at 21:21

Download

wemosshield.ino

Arduino skecth for testing shield

ino - 2.02 kB - 12/28/2018 at 12:49

Download

  • Set speed command as Float number

    Angelote01/14/2019 at 19:43 0 comments

    Set speed  as usteps/s command  as float 4 bytes (24,8)format added

    #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 0x07
    #define MOTOR_SET_PRESCALER 0x08
    #define MOTOR_SET_WAVE_SCALE 0x09
     

    Update Delphi  client for FT260 I2C DONGLE

  • Now tested with WEMOS D1

    Angelote12/28/2018 at 12:53 0 comments

    I have uploaded a arduino Skecth and its works fine with WEMOS D1.

  • Basic and Optional Components

    Angelote12/26/2018 at 16:25 0 comments

    Wemos Motor Shield

    STLink v2 clone (for developing) firmware can be upload by using any usbserial dongle.

    FT260 (to talk I2c from your PC )

    ch340 usb-serial ttl dongle

View all 3 project logs

View all instructions

Enjoy this project?

Share

Discussions

Angelote wrote 01/10/2019 at 21:14 point

I´m  migrating the development enviroment from Code:Blocks to  EMBitz IDE  which bundles  its own GCC-ARM  compiler version.I will include a stripped version of opencm3 with is opensource and more easy for developing than  ST device library.

  Are you sure? yes | no

Angelote wrote 01/10/2019 at 21:07 point

Hello

You may remove delay statements,I had got  some command overlap issues before, but now All seems i OK.My sofware is all interrupt driven  and  should not block.

Target is the  place to stop, consider, there is not a "Goto" command implemented onto  the microcontroller still.Then you have to command " the rigth direction".

I  still have to write  speed up and down timer interrups acceleration routines but it´s a piece of cake.

Resolution is the number of microsteps  you take each timer overflow .Using the 32msteps as base its posible to switch stepper resolution   "on the fly" keeping a coherent value for the step counter.

Yes there is  fixed 10bits  sine wave table as reference  in FLASh, MOTOR_WAVE _TABLE will scale those values into a writable array, value for this is from 0 to 100, (percentage of fixed value).Probably I will make the fixed table  user writable for microstepping calibration,as we know as stepper has its own optimized wave.

There is still a lot of work but I enjoy it.

  Are you sure? yes | no

julienhogert wrote 01/10/2019 at 17:12 point

Hello ! Thank you so much for the job you've done ! For a long time I was expecting what you did ! I made a little library to integrate your code. you can find it here : https://github.com/julienhogert/WEMOS-MOTOR-SHIELD-I2C-STEPPER/tree/master/arduino
It's very basic, but just made it to be more convenient !
I have some questions :
Why did you put  delay(5), in the i2c command?

Why do you have to inverse speed when you already set the Target?
I will probably tweak it in the library to have only positive values.

why did you invert the resolution? Resolution 1-> 32 msteps 2->16 4->8 8->4 counter is always 32 microsteps resolution. I made a function to put it in a more convenient way (1:full step, 2:half, 4:quarter...)
You put: voltage sinoidal microstepping. does it mean that we can manage the current/voltage/torque of the stepper?
Once again, thank you so much for your job,
I can only help with the "easy part" of the code, but if you need it, I'll be there ! Thanks,
Julien  

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates