Dotter — большой матричный принтер на Arduino


Dotter — самодельный матричный принтер под управлением контроллера Arduino Uno.
В конструкции используется три шаговых двигателя: два для продвижения бумаги, а третий для позиционирования каретки.
На каретке установлена сервомашинка, по мере необходимости, толкающая маркер, который и ставит точки на листе бумаги.
Управление двигателями происходит по командам с компьютера от программы на Processing-е.

Программа для Arduino

/*
 * Created by Nikodem Bartnik
 * nikodembartnik.pl
 * If you want to shar this project remember to put link to the original project and my website
 * thank you
 * Happy making!
 * Because of SD library file names must be max 8 character and file extension max 3 character long (i.e. print.gco)
 */
#include "Motor.cpp"
#include "config.h"
#include <Servo.h>

Motor motorX(2, 3, 4, 5);
Motor motorY(8, 9, 10, 11);

Motor motorZ(18, 19, 20, 21);
Motor motorE(22, 23, 24, 25);
Servo servo;
bool currentSide = false;
int last_line_steps = 0;
bool first_trace = true;
String command;
void setup() {

Serial.begin(9600);
servo.attach(7);

servo.write(50);

}

void loop() {

while (Serial.available()){
  delay(10);
  char command_char = Serial.read();
  if (command_char == '#') {break;}
  command += command_char;
  }
  if (command.length() > 0) {
    if(command.equals("1")){
      for(int i = 0; i < 50; i++){
      motorX.oneStep(1);
      last_line_steps++;
      delay(3);
      }
      servo.write(20);
      delay(200);
      servo.write(50);

    }else if(command.equals("0")){
      for(int i = 0; i < 50; i++){
      motorX.oneStep(1);
      last_line_steps++;
      delay(3);
      }
    }else if(command.equals("2")){
      for(int a = 0; a < last_line_steps; a++){
          motorX.oneStep(0);
        delay(3);
      }
      motorX.disableCoils();
      last_line_steps = 0;

      for(int b = 0; b < 60; b++){
     motorY.oneStep(0);
     delay(3);
    }
    motorY.disableCoils();
    }
    command = "";
  }
  }

Программа для Processing-а

import processing.serial.*;
Serial serial;
PImage img;
String file_path;
Boolean file_choosed = false;
String command_line;
//#whenYouDontKnowHowToNameTheVariable
boolean there_will_be_a_dot_in_this_line;
int last_line_steps = 0;
int delay_this_line = 0;
boolean pressed = false;
String portName;
void setup() {
  size(400, 210);
  background(255,255);

portName = Serial.list()[1];
      serial = new Serial(this, portName, 9600);



}
void draw() {
  fill(255);
  rect(-1,-1, 401, 211);
  //open file button
   fill(255);
   rect(10,10, 140, 30);
   fill(0);
   text("OPEN IMAGE", 40,30);

   //open serial
   fill(255);
   rect(10,50, 140, 30);
   fill(0);
   text("OPEN SERIAL", 40,70);

   //load paper
   fill(255);
   rect(10,90, 140, 30);
   fill(0);
   text("LOAD PAPER", 40,110);

   //stop
   fill(255);
   rect(10,130, 140, 30);
   fill(0);
   text("STOP", 63,150);
   fill(255);

   fill(0);
   text("MADE BY NIKODEM BARTNIK \n                10.2017", 10,185);
   text("THIS PROJECT IS CALLED DOTER \n GOOGLE IT TO FIND MORE INFO", 180, 90);

 if(mouseButton == LEFT){
  if(mouseX > 10 && mouseX < 10 + 140 && mouseY > 10 && mouseY < 10 + 30 && pressed == false){
    if(serial != null){
   selectInput("Select a file to process:", "fileSelected");
   pressed = true;
    }else{
      print("Firstly connect to serial port");
    }
  }else if(mouseX > 10 && mouseX < 10 + 140 && mouseY > 50 && mouseY < 50 + 30 && pressed == false){
      //if you can't connect to serial port, change [1] to oder number that you have your arduino on


   pressed = true;

  }else if(mouseX > 10 && mouseX < 10 + 140 && mouseY > 90 && mouseY < 90 + 30 && pressed == false){
    try{
   serial.write("load paper#");
    }catch(Exception e){
    }
   pressed = true;

  }

 }


  if(file_choosed){
    image(img, 0, 0);
  img.loadPixels();
  println("Width: " + img.width);
  println("Height: " + img.height);
  for (int y = 0; y < img.height; y++) {
    boolean there_is_a_dot = false;
    for (int x_temp = 0; x_temp < img.width; x_temp++) {
      if (img.pixels[x_temp + y * img.width] >= color(128)) {
        there_is_a_dot = true;
      }
    }
    if(there_is_a_dot){
      there_will_be_a_dot_in_this_line = true;
    for (int x = 0; x < img.width; x++) {
      if(there_will_be_a_dot_in_this_line){
      if (img.pixels[x + y*img.width] >= color(128)) {
        serial.write("0#");
        print("0");
        last_line_steps++;
        delay(170);
      }
      else {
        print("1");
        serial.write("1#");
        last_line_steps++;
        delay(380);
      }

      there_will_be_a_dot_in_this_line = false;
    for (int xyz = x+1; xyz < img.width; xyz++) {
        if (img.pixels[xyz + y*img.width] <= color(128)) {
       there_will_be_a_dot_in_this_line = true;
      }



    }

    }
    }
    }
   // command_line += "#";
   // serial.write(command_line);
  //  command_line = "";
   // while(serial.readStringUntil('\n') ==  null){};

    println("");

    serial.write("2#");
    delay(last_line_steps * 170);
    delay_this_line = 0;
    last_line_steps = 0;
  }
  file_choosed = false;
  }
}

void fileSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
    file_path = "";
  } else {
    println("User selected " + selection.getAbsolutePath());
    file_path = selection.getAbsolutePath().toString();
    img = loadImage(file_path);
    file_choosed = true;

  }
}

void mouseReleased() {
  pressed = false;
}

Ссылки
Dotter - huge Arduino based dot matrix printer

По теме
3D-принтер из старых DVD
Farmbot - открытый проект робота-садовника на базе Raspberry Pi и Arduino
Простой ЧПУ под управлением Arduino

Arduino
Ардуино что это и зачем?
Arduino, термины, начало работы
КМБ для начинающих ардуинщиков
Состав стартера (точка входа для начинающих ардуинщиков)


Добавить комментарий

Arduino

Что такое Arduino?
Зачем мне Arduino?
Начало работы с Arduino
Для начинающих ардуинщиков
Радиодетали (точка входа для начинающих ардуинщиков)
Первые шаги с Arduino

Разделы

  1. Преимуществ нет, за исключением читабельности: тип bool обычно имеет размер 1 байт, как и uint8_t. Думаю, компилятор в обоих случаях…

  2. Добрый день! Я недавно начал изучать программирование под STM32 и ваши уроки просто бесценны! Хотел узнать зачем использовать переменную типа…

3D-печать AI Android Arduino Bluetooth CraftDuino DIY IDE iRobot Kinect LEGO OpenCV Open Source Python Raspberry Pi RoboCraft ROS swarm ИК автоматизация андроид балансировать бионика версия видео военный датчик дрон интерфейс камера кибервесна манипулятор машинное обучение наше нейронная сеть подводный пылесос работа распознавание робот робототехника светодиод сервомашинка собака управление ходить шаг за шагом шаговый двигатель шилд юмор

OpenCV
Робототехника
Будущее за бионическими роботами?
Нейронная сеть - введение