Arduino 的 GRBL 库 – 使用 Arduino 的 IDE 直接烧写 GRBL 到您的 Arduino

GRBL Arduino Library – Use the Arduino IDE to flash GRBL directly to your Arduino

We have created an Arduino Library of the popular GRBL g-code Interpreter. A great little application that turns your Arduino into a very capable CNC machine.

GRBL,是广受欢迎的  G 代码解释器型 Arduino 库。一个很棒的小应用程序,借助它,可以把你的 Arduino 变成一个非常能干的 CNC 控制器。

This library makes it so much easier to install GRBL onto your Arduino. No more issues with making HEX files or trying to find a way to upload the Hex file to your board. Simply install the library and open the right example sketch for your Arduino.

这个库使得安装 GRBL 到您的 Arduino 容易得多。无需生成 HEX 文件,也无需努力寻找将 HEX 文件上传到你的主板的方法了。只需安装这个库文件,然后打开 Arduino 相应的 sketch 示例文件。

如何安装:

  • 从 GitHub 下载库文件:GRBL Arduino Library
  • 解压缩库文件,然后将解压缩后的文件夹复制到你的 Arduino 软件安装目录下的 Libraries 文件夹内。例如 C:\arduino-1.0.3\libraries\;
  • 将该文件夹重命名为“GRBL”;
  • 打开 Arduino IDE;
  • 点击以下菜单:文件 -> 实例 -> GRBL -> Arduino Uno
  • 将 sketch 上传到你 Arduino Uno 板。

如果你对库文件的源代码感兴趣,可以点击此处获取。

配置 Grbl

Grbl has a system ‘$’-command to tweak the settings and trigger runtime commands. Connect to Grbl using the serial terminal of your choice (baud rate 9600 unless you changed that in config.h) as 8-N-1 (8-bits, no parity, and 1-stop bit.) Once connected you should get the Grbl-prompt, which looks like this:

Grbl 有一个系统“$” – 命令来调整设置和触发运行命令。使用您所选择的串行终端连接 Grbl(默认 波特率 9600 除非你在 config.h 更改过)8-N-1(8 位,无奇偶校验,1 停止位)一旦连接你会收到 Grbl 提示,就像这样:

Grbl 0.8c ['$' for help]

Type $ and press enter. You should not see any local echo of the $ and enter, but Grbl should respond with a help message:

输入 $ 并按回车键。Grbl 会返回一些帮助信息: 继续阅读“配置 Grbl”

关于 Grbl

Grbl is a free, open source, high performance software for controlling the motion of machines that move, that make things, or that make things move, and will run on a straight Arduino. If the maker movement was an industry, Grbl would be the industry standard.

Grbl 是一个免费,开源的,用于控制机器移动的高性能运动软件,让事物,或使物体运动,并将直接在 Arduino 上运行。如果创客运动是一个产业,那么 Grbl 将成为行业标准。

Most open source 3D printers have Grbl in their hearts. It has been adapted for use in hundreds of projects including laser cutters, automatic hand writers, hole drillers, graffiti painters and oddball drawing machines. Due to its performance, simplicity and frugal hardware requirements Grbl has grown into a little open source phenomenon.

大多数开源 3D 打印机是基于 Grbl 为核心。其已经适用于成百上千的项目包括激光切割机,自动手作家、钻孔机,涂鸦画家和怪异的绘图机。由于其高效,简单和极低的硬件要求 Grbl 已经成为一个小的开源事迹。

In 2009, Simen Svale Skogsrud graced the open-source community by writing and releasing the early versions of Grbl to everyone (inspired by the Arduino GCode Interpreter by Mike Ellery). Since 2011, Grbl is pushing ahead as a community-driven open-source project under the pragmatic leadership of Sungeun K. Jeon Ph.D.

2009 年,Simen Svale Skogsrud  受惠于开源社区的贡献编写并向所有人发布了 Grbl 的早期版本(灵感来自于 Mike Ellery 的 Arduino G 代码解释器)。2011 年以来,Grbl 在 Sungeun K. Jeon 博士务实的领导下作为一个社区驱动的开源项目在推进。

连接 Grbl

This wiki is intended to provide various instructions on how to connect to grbl in various ways. Please feel free to contribute more up-to-date or alternative methods.

这个维基旨在提供如何以不同的方式连接 Grbl 的各种说明。请随时提供更多最新的或替代的方法。

Grbl 的针脚

Pin diagram for Grbl v0.8 and v0.9 with the traditional layout: (NOTE: The probe A5 pin is only available in Grbl v0.9.)

Grbl V0.8 和 V0.9 与传统的布局引脚图(注:探头 A5 引脚仅在 Grbl v0.9 提供。)

68747470733a2f2f646c2e64726f70626f782e636f6d2f752f323232313939372f4772626c5f50696e5f4469616772616d2e706e67

For Grbl v0.9 with variable spindle PWM ENABLED: (NOTE: The Z-limit and the spindle enable pin are swapped, because we had to access the hardware PWM on D11 for variable spindle PWM output to work.) We are still updating this pin configuration at the moment by weighing future options. We’d like to only change the pins once. Stay tuned!

68747470733a2f2f646c2e64726f70626f7875736572636f6e74656e742e636f6d2f752f323232313939372f4772626c5f50696e5f4469616772616d5f76302e392e706e67

First, to connect your stepper motors to Grbl, you’ll need some stepper motor drivers to power the steppers and connect your driver inputs to the Arduino controller pins. There are a number of drivers that can do this, available as fully pre-built, partially pre-built, or completely DIY. There are some examples farther down the page. The stepper drivers will need to share the stepper enable pin (D8) to their respective enable pins, while the direction and step pulse pins (D2-D7) will need to be connected to their respective pins on the drivers. Just make sure that all of your drivers and the Arduino share a common ground (star grounded with your motor driver power). This is about all you’ll need to get started.

Afterwards, once you decide that you’re ready or would like to enable homing and/or hard limits, you’ll need to connect a normally-open limit switch to each of the limit pins (D9-D11). Homing and hard limits use the same switches. These limit pins are already held high with an internal pull-up resistor, so all you have to do is wire them to ground. So when you close a switch, the switch will pull the limit pin to ground. If you’d like to have hard limit switches on both ends of travel of an axis, just wire two limit switches in parallel to the axis limit pin and ground. Make sure you have the switches installed before attempting to perform a homing cycle, and make sure you practice good wiring methods to minimize external electric noise on the input pins.

之后,一旦你决定,你准备好了,或者要启用归位和/或硬限制,你需要连接一个常开限位开关到每个限位销(D9-D11)。归巢和硬限制使用相同的开关。这些限制引脚已经高举带有内部上拉电阻,所以你要做的就是把他们接地。所以,当你关闭开关,该开关将拉的限位引脚接地。如果你想在轴的行程两端都添加硬限位开关,只需将两个限位开关并联连接到该轴的限位引脚并接地。在试图执行一个归航周期之前请确保您已经安装了开关,并确保你养成良好的布线方式,以尽量减少输入引脚上的外部电噪声。

In Grbl v0.8 and later, there are pin-outs of the cycle start, feed hold, and reset runtime commands, so you can have physical control buttons are your machine. Just like the limit pins, these pins are held high with an internal pull-up resistor, so all you have to do is connect a normally-open switch to each pin and to ground. Again make sure you practice good wiring methods to minimize external electric noise on the input pins.

在 Grbl V0.8 及更高版本,有循环启动的引脚,进给保持,和复位运行命令,这样你可以为你的机器添加物理控制按键。就像限位引脚,这些引脚具有内部上拉电阻高高举起,因此,你所要做的就是将一个常开开关连接到每个引脚并接地。再次确保你已养成良好的布线方式,以尽量减少输入引脚上的外部电噪声。

If you have a desire or need for spindle or coolant control, Grbl will toggle these output pins (D12, D13, A3) high or low, depending on the G-code commands you send to Grbl. With v0.9 and variable spindle PWM enabled, the D11 pin will output a range of voltages from 0V to 5V depending the spindle speed G-code command. 0V indicates spindle off in this case. Since these pins are all application dependent in how they are used, we’ll leave it to you to determine how to control and use these for your machine. You can also hack the spindle and coolant control source files to easily alter how they work and then compile and upload your modified Grbl through the Arduino IDE.

如果你需要主轴或冷却液控制的要求,Grbl 将切换这些输出引脚(D12,D13,A3)的高低状态,根据 G 代码指令发送到 Grbl。随着 V0.9 版本可变速主轴 PWM 的启用,根据主轴转速G代码指令 D11 引脚将输出从 0V 到 5V 的电压范围。在这种情况下 0V 表示主轴关闭。以后这些引脚,如何使用它们都取决于所有应用程序,如何使用这些控制你的机器由你决定。

Arduino 的开源 CNC 控制器 GRBL (G 代码解释器)

Opensource CNC controller written for Arduino’s (G-code interpreter GRBL)
Arduino 的开源 CNC 控制器 GRBL (G 代码解释器)

Traditional CNC machines used old-fashioned printer / parallel ports to connect to a computer.The computer then sends the signals to the motor’s over individual cables.
传统的数控机床使用老式打印机 / 并行端口连接到计算机。然后计算机通过单独的连线将信号发送到马达端。

So why would you want to use a Arduino powered CNC controller?
那么 为什么你会选择 Arduino 驱动的 CNC 控制器呢?

Well the team from Dank that developed the software called Grbl have a few good reason for doing so. Here are their reasons..
好的,来自 Dank 的软件开发团队称 Grbl 有充份的理由让你这样做。这是他们给出的理由…

Who should use Grbl
谁会使用 Grbl

  • Makers who do milling and need a nice, simple controller for their system
    制造商的铣削系统需要一个友好的、 简单的控制器
  • People who loathe to clutter their space with legacy PC-towers just for the parallel-port
    那些讨厌杂乱的旧的塔式 PC 并行端口的人
  • Tinkerers who need a controller written in tidy, modular C as a basis for their project.
    超级玩家需要一个可写入的控制器,为他们以 C 作为基础的模块化项目

I can actually think of a lot more than just those.With a bit of tinkering you can actually make your CNC machine run in headless mode where you just upload your design to the Arduino and the machine will do the rest without the need of a PC.
事实上,我能想到的不仅仅是这些还有更多,稍微改造下,你可以让你的数控机床在无上位机的模式运行,只要上传你的 Arduino 设计,机器无需再连接计算机就会工作。

You could also add a Wireless connection to the Arduino allowing you to remotely control your CNC machine from a mobile device.
你还可以为 Arduino 添加一个无线连接,以允许你从移动设备远程控制您的数控机床。

关于 Arduino 版数控雕刻机的点滴

一直以来我都相信自己可以把这台机器推荐给世上绝大部分的人,也想以此带动一部分人摆脱无聊、灰暗、枯躁、麻木、一成不变的生活,我的初衷是希望他们更有情趣,更有意义,更积极向上,更精彩的生活着。可是现在的我开始怀疑自己,我是不是有点盲目乐观,它会不会是一个小众化的产品?

今天分享下关于 Arduino 版数控雕刻机的东西,对于密切关注 Arduino 的朋友,可能这已经算不上是什么新鲜的东西了。而我亦是后知后觉,在了解了这个信息之后几个月才来分享,也是懒惰到不行了。小小狡辩一下,在知道这个信息后我也准备自己动手做一台,采购电路,验证软件与电路的可行性后,我就没日没夜的在电脑上画图,反复修改。不堪回首的一些日子之后,雕刻机的机械部分终于定稿,出图纸,然后交给事先联系好的淘宝卖家打样,这才总算可以平静下来,心情轻松的敲敲键盘把想说的分享出来。 继续阅读“关于 Arduino 版数控雕刻机的点滴”

Arduino 蓝牙控制 L298N 直流电机驱动板附代码

一段蓝牙控制车子的代码,直流电机驱动板为 L298N,稍后补充更详细的资料。

    int Input1 = 13;    // motor A
    int Input2 = 12;
    int EnA = 10;

    int Input3 = 11;    // motor B
    int Input4 = 8;
    int EnB = 9;
    
    const int pinRx = 0;    //蓝牙数据传输接口(3.3V)
    const int pinTx = 1;
    
    int dir;        //运行控制
        
    void setup()
    {
      Serial.begin(9600);    //设置波特率
      
      pinMode(Input1, OUTPUT);   //左轮端口模式设置
      pinMode(Input2, OUTPUT);   //左轮端口模式设置
      pinMode(EnA, OUTPUT);
      pinMode(Input3, OUTPUT);   //右轮端口模式设置
      pinMode(Input4, OUTPUT);   //右轮端口模式设置
      pinMode(EnB,OUTPUT);
            
      digitalWrite(Input1, LOW);   //左轮端口模式初始化设置
      digitalWrite(Input2, LOW);   //左轮端口模式初始化设置
      digitalWrite(Input3, LOW);   //右轮端口模式初始化设置
      digitalWrite(Input4, LOW);   //右轮端口模式初始化设置
      
      pinMode(pinTx, OUTPUT);
      pinMode(pinRx, INPUT);
    }
    
    void loop()
    {
      dir = Serial.read();

      switch(dir)
      {
        case 'f':
           m_forward();
           break;
        case 'b':
           m_back();
           break;
        case 'l':
           m_left();
           break;
        case 'r':
           m_right();
           break;
        default:
           m_stop();
      }
    }
      void m_forward()    //前进
      {
        digitalWrite(Input1, LOW);
        digitalWrite(Input2, HIGH);
        analogWrite(EnA, 250);
        digitalWrite(Input3, LOW);
        digitalWrite(Input4, HIGH);
        analogWrite(EnB, 250);
        Serial.println("forward!");
        delay(1000);
      }
      
      void m_back()      //后退
      {
        digitalWrite(Input1, HIGH);
        digitalWrite(Input2, LOW);
        analogWrite(EnA, 250);
        digitalWrite(Input3, HIGH);
        digitalWrite(Input4, LOW);
        analogWrite(EnB, 250);
        Serial.println("back!");
        delay(1000);
      }
      
      void m_left()      //左拐弯
      {
        digitalWrite(Input1, HIGH);
        digitalWrite(Input2, LOW);
        analogWrite(EnA, 250);
        digitalWrite(Input3, LOW);
        digitalWrite(Input4, HIGH);
        analogWrite(EnB, 250);
        Serial.println("left!");
        delay(1000);
      }
      
      void m_right()     //右拐弯
      {
        digitalWrite(Input1, LOW);
        digitalWrite(Input2, HIGH);
        analogWrite(EnA, 250);
        digitalWrite(Input3, HIGH);
        digitalWrite(Input4, LOW);
        analogWrite(EnB, 250);
        Serial.println("right!");
        delay(1000);
      }
      
      void m_stop()      //停车
      {
        digitalWrite(Input1, LOW);
        digitalWrite(Input2, LOW);
        digitalWrite(Input3, LOW);
        digitalWrite(Input4, LOW);
        Serial.println("stop!");
        delay(1000);
      }

Arduino 教程之:步进电机控制

/*
Stepper Motor Control – one revolution

步进电机控制 – 一圈

This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 – 11 of the Arduino.

这个程序驱动单极或双极步进电机。电机连接到 Arduino 的数字引脚 8 – 11。

The motor should revolve one revolution in one direction, then
one revolution in the other direction.

电机应朝一个方向旋转一圈,然后朝相反方向旋转一圈。

Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe

*/
继续阅读“Arduino 教程之:步进电机控制”

Arduino 教程之:XBee 无线通信

借助 XBee 扩展板我们可以很方便地将 XBee 模块连接到 Arduino 上,XBee 模块的工作原理也非常简单,它与 Arduino 之间其实就是通过串行接口(即 Tx 和 Rx 引脚)进行通信。对于简单的点对点通信来讲,只需要通过串行接口向 XBee 模块写数据就可以实现数据的发送;当 XBee 模块通过无线通道接收到数据时,通过读串行接口可以很方便地获得这些数据。

原理弄清楚之后,其实我们可以将 XBee 模块看成是 Arduino 的串口,通过相应的串口操作函数来实现数据的接收和发送。首先请按照 Arduino XBee 模块使用手册中的说明配置好你的两个 XBee 模块,然后将相应的跳线连接到 XBee 一端: 继续阅读“Arduino 教程之:XBee 无线通信”

Arduino 教程之:串口输入

串行通信是实现 PC 机与微控制器进行交互的最简单的办法。之前的 PC 机上一般都配有标准的 RS-232 或者 RS-422 接口来实现串行通信,但现在这种情况已经发生了一些改变,大家更倾向于使用 USB 这样一种更快速但同时也更加复杂的方式来实现串行通信。尽管在有些计算机上现在已经找不到 RS-232 或者 RS-422 接口了,但我们仍可以通过 USB/串口 或者 PCMCIA/串口 这样的转换器,在这些设备上得到传统的串口。

通过串口连接的 Arduino 在交互式设计中能够为 PC 机提供一种全新的交互方式,比如用 PC 机控制一些之前看起来非常复杂的事情,像声音和视频等。很多场合中都要求 Arduino 能够通过串口接收来自于 PC 机的命令,并完成相应的功能,这可以通过 Arduino 语言中提供的 Serial.read() 函数来实现。 继续阅读“Arduino 教程之:串口输入”