Welcome! Log In Create A New Profile

Advanced

turntable G-code issue.

Posted by GRAYWOLF 
turntable G-code issue.
October 27, 2018 07:09AM
I'm working on a turntable project which uses an M5Stack to communicate with an arduino 328 grbl controller using this code.
// Example for M5Stack StepMotor Module (I2C verison)
// 2018/6/27 JimmyLai
#include 
#include 

void setup() {
  // put your setup code here, to run once:
  M5.begin();
  Wire.begin();
  Serial.begin(115200);
  m5.Lcd.setTextColor(WHITE, BLACK);
  m5.Lcd.setTextSize(2);
  m5.lcd.setBrightness(100);
  M5.Lcd.setCursor(4, 10);
  M5.Lcd.println("StepMotor Test: 0x70/0x71");
  M5.Lcd.setCursor(4, 30);
  M5.Lcd.println("Press A: 0x70");
  M5.Lcd.setCursor(4, 50);
  M5.Lcd.println("Press B: 0x71");
}

void SendByte(byte addr, byte b) {
  Wire.beginTransmission(addr);
  Wire.write(b);
  Wire.endTransmission();
}

void SendCommand(byte addr, char *c) {
  Wire.beginTransmission(addr);
  while ((*c) != 0) {
    Wire.write(*c);
    c++;
  }
  Wire.write(0x0d);
  Wire.write(0x0a);
  Wire.endTransmission();
}

void loop() {
  if (digitalRead(39) == LOW)  // A button
  {
    while (digitalRead(39) == LOW) delay(1);
    SendCommand(0x70, "G1 X0Y0Z200 F500");
    while (digitalRead(39) == HIGH) delay(1);
    SendCommand(0x70, "G1 X0Y0Z0 F0");
  

  }
  // Get Data from Module.
  Wire.requestFrom(0x70, 1);
  if (Wire.available() > 0) {
    int u = Wire.read();
    if (u != 0) Serial.write(u);
  }
  Wire.requestFrom(0x71, 1);
  if (Wire.available() > 0) {
    int u = Wire.read();
    if (u != 0) Serial.write(u);
  }
  delay(1);
  // Send Data to Module.
  while (Serial.available() > 0) {
    int inByte = Serial.read();
    SendByte(0x70, inByte);
    SendByte(0x71, inByte);
  }
}

But I'm having trouble understanding the G-Code.

What code to I need to send to get the turntable to turn 360 using a standered nema 17 motor?
currently the code spins the nema 17 a few tuns and stops is causing it to humm.

Can anyone give me some help and pointers please?
Re: turntable G-code issue.
October 27, 2018 07:53AM
void loop() {
if (digitalRead(39) == LOW) // A button
{
while (digitalRead(39) == LOW) delay(1);
SendCommand(0x70, "G1 X0Y0Z200 F500");
while (digitalRead(39) == HIGH) delay(1);
SendCommand(0x70, "G1 X0Y0Z0 F0");


no de-bounce here... a real button press will go low,high,low,high low high ...... low low low...

also this loop is really short, I suspect you getting serial buffer over runs.

re gcode Im presuming its close enough to reprap gcode...

G1 X0Y0Z200 F500 just move the Z 200 steps at 500/60 mm/s how many steps you need to turn for 1 revolution depends on your hardware. Is the there any gearing or belts or is the turntable directly mounted on the stepper shaft. Also is there any micro stepping. First off I would reduce the F to 60 ie 1 step/s slow things down so you can see what is going on.

now before you send a G1 you should set the current mode, absolute or relative positioning
If absolute G90 then Z200 will move to position 200, and no matter how many more times you send G1 Z200 it will not move from the absolute position of 200 and when G1 Z0 is sent it will return back to position 0

if relative G91 then each G1 Z200 will move it a further 200 steps

your button high second command doesnt make sense
G1 X0Y0Z0 F0 move to Z0, but do it at a feed rate of 0, ie dont move.?

your code also doesn't make sense... this may be the implementation on your controller

but the following to me reads as

while (digitalRead(39) == LOW) delay(1); // while the button is low, delay
SendCommand(0x70, "G1 X0Y0Z200 F500"); //always send this command as it is outside of the while
while (digitalRead(39) == HIGH) delay(1); // while the button is high delay
SendCommand(0x70, "G1 X0Y0Z0 F0"); // always send this as this command as is outside of the while

perhaps it should be

while (digitalRead(39) == LOW) {
delay(1);
SendCommand(0x70, "G1 X0Y0Z200 F500");
}
while (digitalRead(39) == HIGH) {
delay(1);
SendCommand(0x70, "G1 X0Y0Z0 F500");
}

but even that is not nice as it will keep sending g code constantly... most of which will do nothing. (presuming absolute positioning)


Are you trying to get it to move to a particular position on button press or get it to spin?

Edited 2 time(s). Last edit at 10/27/2018 08:01AM by Dust.
Re: turntable G-code issue.
October 27, 2018 08:48AM
Debounce is supposed to be handled else whare

Thanks for taking the time to look, Yes it doesn't make sense I was blindly sending random commands!

thanks, will drop the F500 to F60 and try again, still trying to clock the nema so that I can fine tune some settings.


I need it to three modes.

Mode 1 - do a full 360 and stop.

Mode 2 - When button pressed, make one step (1.8 degrees?) stop, fire a photo (i will sort this out in another code), wait while camera saves images (sony alphas are so slow) then repeat

Mode 3 - When button pressed, make one step (1.8 degrees?) stop, fire a photo (i will sort this out in another code), wait while camera saves images (sony alphas are so slow) then prompt user to press button to continue to next step.

This is sort of a 3d scanner is kind of design.

Edited 2 time(s). Last edit at 10/27/2018 09:00AM by GRAYWOLF.
Re: turntable G-code issue.
October 27, 2018 01:50PM
This is my current loop, works better but travel is not as expected (stops at random locations.)
 if (digitalRead(39) == LOW)  // A button
  {
    while (digitalRead(39) == LOW) delay(1);
    SendCommand(0x70, "G91 X0Y0Z1 F30");

  }

Edited 1 time(s). Last edit at 10/27/2018 02:19PM by GRAYWOLF.
Re: turntable G-code issue.
October 28, 2018 01:05PM
So after issueing
G91 X0Y0Z0.1 F1

I get a a rotation of 450 degrees or 250 steps @ 1.8 degrees.
Sorry, only registered users may post in this forum.

Click here to login