Commit 08c5ec67 authored by Ismael Larrea Bravo's avatar Ismael Larrea Bravo
Browse files

Adding documentation about programming, circuit design and fabrication

parent b752b678
Pipeline #222368 passed with stage
in 12 seconds
//#include <SoftwareSerial.h>
//SoftwareSerial custom(10,9);
// Program to control the test laser endstops for a cnc machine X and Y axis
// Made by Isma LB, released under CC0
#define PHOTOTRANSISTOR_PIN_X A1 //pin 12
#define LASER_PIN_X 10 //pin 2
#define ENDSTOP_PIN_X 3 //pin 10
#define PHOTOTRANSISTOR_PIN_Y 0 //pin 13
#define LASER_PIN_Y 9 //pin 3
#define ENDSTOP_PIN_Y 2 //pin 11
#define PHOTOTRANSISTOR_THRESHOLD 500
#define SIGNAL_DELAY 275
bool isEndstopPressedX = false;
bool isEndstopPressedY = false;
bool onX = false;
bool onY = false;
bool sensingX = false;
bool sensingY = false;
unsigned long xOnUntil = 0;
unsigned long yOnUntil = 0;
bool isEndstopPressed(uint8_t pin, bool *flag ){
if(! digitalRead(pin) && !*flag){
//End stop activated
*flag = true;
return true;
}
if(digitalRead(pin)){
*flag = false;
}
return false;
}
void setup() {
CLKPR = (1 << CLKPCE);
CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
pinMode(PHOTOTRANSISTOR_PIN_X,INPUT);
pinMode(PHOTOTRANSISTOR_PIN_Y,INPUT);
pinMode(ENDSTOP_PIN_X,INPUT);
pinMode(ENDSTOP_PIN_Y,INPUT);
pinMode(LASER_PIN_X,OUTPUT);
pinMode(LASER_PIN_Y,OUTPUT);
}
bool test = false;
void loop() {
if( xOnUntil + 1 <= millis() && isEndstopPressed(ENDSTOP_PIN_X,&isEndstopPressedX)){
onX = true;
}
if( yOnUntil + 1 <= millis() && isEndstopPressed(ENDSTOP_PIN_Y,&isEndstopPressedY)){
onY = true;
}
if(onX){
digitalWrite(LASER_PIN_X, HIGH);
if(analogRead(PHOTOTRANSISTOR_PIN_X)>PHOTOTRANSISTOR_THRESHOLD){
sensingX = true;
}
if(sensingX && analogRead(PHOTOTRANSISTOR_PIN_X)<PHOTOTRANSISTOR_THRESHOLD){
//send signal
digitalWrite(ENDSTOP_PIN_X,LOW);
pinMode(ENDSTOP_PIN_X,OUTPUT);
sensingX = false;
onX = false;
xOnUntil = millis() + SIGNAL_DELAY;
}
}
else{
digitalWrite(LASER_PIN_X, LOW);
}
if(xOnUntil <= millis()){ //off
pinMode(ENDSTOP_PIN_X, INPUT);
}
if(onY){
digitalWrite(LASER_PIN_Y, HIGH);
if(analogRead(PHOTOTRANSISTOR_PIN_Y)>PHOTOTRANSISTOR_THRESHOLD){
sensingY = true;
}
if(sensingY && analogRead(PHOTOTRANSISTOR_PIN_Y)<PHOTOTRANSISTOR_THRESHOLD){
digitalWrite(ENDSTOP_PIN_Y,LOW);
pinMode(ENDSTOP_PIN_Y,OUTPUT);
sensingY = false;
onY = false;
yOnUntil = millis() + SIGNAL_DELAY;
}
}
else{
digitalWrite(LASER_PIN_Y, LOW);
}
if(yOnUntil <= millis()) {
//turn signal off
pinMode(ENDSTOP_PIN_Y, INPUT);
}
}
This diff is collapsed.
This diff is collapsed.
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content=""> <meta name="description" content="Here you can learn how we made our grup machine to enable laser zeroing">
<meta name="author" content=""> <meta name="author" content="FabAcademy Students 2021">
<title>Machine</title> <title>Machine</title>
...@@ -90,8 +90,48 @@ ...@@ -90,8 +90,48 @@
<p>See the final result of our group. <p>See the final result of our group.
<img class="image" src="img/vending1.jpg" height="200" alt="vending"> <img class="image" src="img/vending1.jpg" height="200" alt="vending">
</p> </p>
<section>
<h2>Making the circuit board</h2>
<p>As our machine was centered around laser-zeroing we need to 'hack' the limit switches, as we hope that the laser can add precision on top of the physical switches by eliminating the bounce effect issues.</p>
<p>The board has to be capable of sensing when the limit switch is pressed and turn on the laser and then sense the interruption and act as a limit switch.</p>
<p>With Camilo we sketch a simple diagram that uses the ATtiny44 as source of logic some pulldown resistors for the phototransistors and some diodes to make sure the board does not interfere too much with the sensing from the Arduino UNO.</p>
<div class="row">
<img src="./img/machine/mm-board-sketch.jpg" alt="Sketch of the board made by Camilo and I" class="img-responsive col-4 col-xs-6"/>
<img src="./img/machine/mm-board-schematic.png" alt="Screenshot of the finished schematic on Eagle" class="img-responsive col-4 col-xs-6"/>
<img src="./img/machine/mm-board-layout.png" alt="Screenshot of the finished schematic on Eagle" class="img-responsive col-4 col-xs-6"/>
</div>
<p>Using Eagle we place the required components and start routing the traces. This process takes me always a while, figuring out the best way to make the traces is difficult.</p>
<a class="btn btn-default" href="./img/machine/mm-board-outline.png" target="_blank" rel="noopener noreferrer">See the board outline</a>
<a class="btn btn-default" href="./img/machine/mm-board-traces.png" target="_blank" rel="noopener noreferrer">See the board traces</a>
<a class="btn btn-default" href="./img/machine/mm-board-traces.png" target="_blank" rel="noopener noreferrer">get the eagle file</a>
<p>Using <a href="http://modsproject.org/" target="_blank" rel="noopener noreferrer">Mods</a> we generate the G-code needed for the traces and start milling, our first attempt was a failure because we were using wrong the auto-level on the <a href="https://github.com/vlachoudis/bCNC" target="_blank" rel="noopener noreferrer">bCNC</a> (software that controls the CNC milling machine). But after some research on the internet, we manage to use a new workflow and use the auto-level properly. The result was that the mill bit only engrave the surfaces of the copper layer and did not crate the traces.</p>
<p>After adjusting the cut depth on the g-code using the same workflow we finally make a good looking circuit board.</p>
<div class="row">
<img src="./img/machine/mm-milling-board.jpg" alt="CNC machine milling the board" class="col-6 col-xs-6" />
<img src="./img/machine/mm-milled-board.jpg" alt="Board milled and ready to be stuffed" class="col-6 col-xs-6" />
</div>
<p>Then the next step was to solder all the components, I started by the micro controller unit, followed by the capacitor, the resistors, diodes and finally the pin headers for the ISP connections.</p>
<div class="row">
<img src="./img/machine/mm-soldering-micro.jpg" alt="Soldering the ATtiny44 to the board" class="col-6 col-xs-6" />
<img src="./img/machine/mm-finished-board.jpg" alt="Finished board after soldering" class="col-6 col-xs-6" />
</div>
</section>
<section id="troubleshooting">
<br>
<hr>
<br>
<h2>Troubleshooting</h2>
<p>Here you cans see the problems that we have and how we solve them.</p>
<h3>Broken pin on the circuit board</h3>
<p>While programming and testing the board we have and inconvenience, one of the pin headers to connect the phototransistor broke, peeling off some traces. Luckily Camilo managed to solder the header again and using super glue we secure everything on place again.</p>
<div class="row">
<img src="./img/machine/mm-borken-board.jpg" alt="Broken traces" class="col-6 col-xs-6" />
<img src="./img/machine/mm-fixing-board.jpg" alt="Fixing the broken board" class="col-6 col-xs-6" />
</div>
</section>
</div>
</div>
</div>
<hr> <hr>
<!-- Footer --> <!-- Footer -->
...@@ -139,8 +179,8 @@ ...@@ -139,8 +179,8 @@
<script src="vendor/bootstrap/js/bootstrap.min.js"></script> <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!-- Contact Form JavaScript --> <!-- Contact Form JavaScript -->
<script src="js/jqBootstrapValidation.js"></script> <!-- <script src="js/jqBootstrapValidation.js"></script>
<script src="js/contact_me.js"></script> <script src="js/contact_me.js"></script> -->
<!-- Theme JavaScript --> <!-- Theme JavaScript -->
<script src="js/clean-blog.min.js"></script> <script src="js/clean-blog.min.js"></script>
......
...@@ -92,6 +92,35 @@ ...@@ -92,6 +92,35 @@
</ul> </ul>
</blockquote> </blockquote>
</header> </header>
<hr>
<section>
<h2>Making the circuit board</h2>
<p>As our machine was centered around laser-zeroing we need to 'hack' the limit switches, as we hope that the laser can add precision on top of the physical switches by eliminating the bounce effect issues.</p>
<p>The board has to be capable of sensing when the limit switch is pressed and turn on the laser and then sense the interruption and act as a limit switch.</p>
<p>With Camilo we sketch a simple diagram that uses the ATtiny44 as source of logic some pulldown resistors for the phototransistors and some diodes to make sure the board does not interfere too much with the sensing from the Arduino UNO.</p>
<div class="row">
<img src="./img/machine/mm-board-sketch.jpg" alt="Sketch of the board made by Camilo and I" class="img-responsive col-4 col-xs-6"/>
<img src="./img/machine/mm-board-schematic.png" alt="Screenshot of the finished schematic on Eagle" class="img-responsive col-4 col-xs-6"/>
<img src="./img/machine/mm-board-layout.png" alt="Screenshot of the finished schematic on Eagle" class="img-responsive col-4 col-xs-6"/>
</div>
<p>Using Eagle we place the required components and start routing the traces. This process takes me always a while, figuring out the best way to make the traces is difficult.</p>
<a class="btn btn-default" href="./img/machine/mm-board-outline.png" target="_blank" rel="noopener noreferrer">See the board outline</a>
<a class="btn btn-default" href="./img/machine/mm-board-traces.png" target="_blank" rel="noopener noreferrer">See the board traces</a>
<a class="btn btn-default" href="./img/machine/main-board.sch" target="_blank" rel="noopener noreferrer" download>get the Eagle .sch file</a>
<a class="btn btn-default" href="./img/machine/main-board.brd" target="_blank" rel="noopener noreferrer" download>get the Eagle .brd file</a>
<p>Using <a href="http://modsproject.org/" target="_blank" rel="noopener noreferrer">Mods</a> we generate the G-code needed for the traces and start milling, our first attempt was a failure because we were using wrong the auto-level on the <a href="https://github.com/vlachoudis/bCNC" target="_blank" rel="noopener noreferrer">bCNC</a> (software that controls the CNC milling machine). But after some research on the internet, we manage to use a new workflow and use the auto-level properly. The result was that the mill bit only engrave the surfaces of the copper layer and did not crate the traces.</p>
<p>After adjusting the cut depth on the g-code using the same workflow we finally make a good looking circuit board.</p>
<div class="row">
<img src="./img/machine/mm-milling-board.jpg" alt="CNC machine milling the board" class="col-6 col-xs-6" />
<img src="./img/machine/mm-milled-board.jpg" alt="Board milled and ready to be stuffed" class="col-6 col-xs-6" />
</div>
<p>Then the next step was to solder all the components, I started by the micro controller unit, followed by the capacitor, the resistors, diodes and finally the pin headers for the ISP connections.</p>
<div class="row">
<img src="./img/machine/mm-soldering-micro.jpg" alt="Soldering the ATtiny44 to the board" class="col-6 col-xs-6" />
<img src="./img/machine/mm-finished-board.jpg" alt="Finished board after soldering" class="col-6 col-xs-6" />
</div>
</section>
<br>
<hr /> <hr />
<h3>End Stops Limit Switches</h3> <h3>End Stops Limit Switches</h3>
<P>End-stops can also be used as limit switches which prevent the machine from attempting to move beyond the physical limits of the <P>End-stops can also be used as limit switches which prevent the machine from attempting to move beyond the physical limits of the
...@@ -119,6 +148,22 @@ ...@@ -119,6 +148,22 @@
<span class="image"><img src="img/w9/imp3.jpg" alt="" height="210"/></span></p> <span class="image"><img src="img/w9/imp3.jpg" alt="" height="210"/></span></p>
<br> <br>
</p> </p>
<hr>
<br>
<section id="troubleshooting">
<br>
<hr>
<br>
<h2>Troubleshooting</h2>
<p>Here you cans see the problems that we have and how we solve them.</p>
<h3>Broken pin on the circuit board</h3>
<p>While programming and testing the board we have and inconvenience, one of the pin headers to connect the phototransistor broke, peeling off some traces. Luckily Camilo managed to solder the header again and using super glue we secure everything on place again.</p>
<div class="row">
<img src="./img/machine/mm-borken-board.jpg" alt="Broken traces" class="col-6 col-xs-6" />
<img src="./img/machine/mm-fixing-board.jpg" alt="Fixing the broken board" class="col-6 col-xs-6" />
</div>
</section>
</div> </div>
<hr> <hr>
</div> </div>
...@@ -182,6 +227,18 @@ ...@@ -182,6 +227,18 @@
</p> </p>
<section id="programming">
<h2>Programming</h2>
<p>The ATtiny44 used on the board need to be programmed to achieve the laser and end switch sensing and react accordantly. I first start using Platformio to write the program as is easier for me use VS code that writhing inn the ArduinoIDE, but some how the SoftwareSerial.h wasn't working on the ATtiny44 when programing with Platformio. And that force me to move to the ArduinoIDE.</p>
<img src="./img/machine/ss-phototransistor-serial-test.jpg" alt="Screenshot of the serial test to debug the code and establish the threshold" class="img-responsive" />
<p>The first step was to make and analog read on the phototransistor pin and establish an approximate threshold to discriminate when the laser was pointing to phototransistor.</p>
<p>The complete code was a bit difficult because you have to check both axis on the same time so it can't uses any <samp>delay()</samp> function.</p>
<img src="./img/machine/mm-meme.jpg" alt="Programming meme that represents my mistake." class="img-responsive" style="float: right; width:45%;" />
<p>After some test it was working as intended but the program wasn't turning the signal off once it was sended, this bug take me a while to solve. I initially think that the state machine of the code was some how on and infinite loop. But after a lunch brake I finally catch my mistake it was a <samp>digitalWrite(ENDSTOP_PIN_X, INPUT)</samp> where it should be <samp>pinMode(ENDSTOP_PIN_X,INPUT)</samp></p>
<a href="./img/machine/laser-zeroing.ino" target="_blank" rel="noopener noreferrer" class="btn btn-default" download>Get the .ino file</a>
</section>
</div> </div>
<hr> <hr>
</div> </div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment