Commit 87e5fc79 authored by Schwarzburg, Klaus's avatar Schwarzburg, Klaus
Browse files

rest

parent 1cc1ce0a
......@@ -60,6 +60,12 @@ It is import to realize that the Arduino will restart every time it connects via
*Note: My inital plan was to use the firmata firmware for this. However, it turned out that there is not a Python firmata API for the customFirmata firmware that supports the accelstepper library (as of 5/2021). In the end, writing a simple serial protocol like this, is not much overhead and removes the dependency on firmata*
## afterthoughts on the selection of microprocessor board
Initially I was only concerned by the maximum number of DIO ports available. However when the project came to its end I became also aware of the memory and speed limitations of the Arduino Uno/Nano boards. In the scetch, the command and report strings fill up almost the full memory (2kB !!!) of the Uno. When I added the OLED option for the wavelength display, I had to shorten some of those strings to make the FW work again and I also had to use a slow OLED access mode of the U8G2 library that is light on memory! With respect to memory, the Arduino Mega would be a better solution far from being maxed out. For this particular project the speed of the Uno/Mega is acceptable. On the other hand, there are the newer ESP32 boards that are mostly compatible with the Arduino IDE code, cost only around 4€ and are waaaaayyyyy better in almost any aspect. The ESP32 boards are roughly a factor of 100x faster, offer more DIO pins, have 2 real 8bit DAC, have WIFI and BT LE built in and 200x more RAM and flash memory. Next time...
*references*
http://www.airspayce.com/mikem/arduino/AccelStepper/
https://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection/
......
#include <AccelStepper.h>
// Controlling the ancient Jobin Yvon (Horiba) HR 460 monochromator with an Arudino Mega and DRV8825 and L298N drivers
// using AccelStepper lib for the wavelength drive
// background: the old hardware board died and there was no replacement available. The HR460 ist still a solid mono, with full motorized slits, turret and in/out ports.
......@@ -16,16 +15,30 @@
// repeat for the other grating
// re-upload the sketch
#define FW_STRING "HR460 Arduino Firmware V0.1 2021 , ks@HZB"
#include <AccelStepper.h>
#define OLED // undefine to not use the oled feature
#ifdef OLED // this uses the U8G2 library: https://github.com/olikraus/u8g2
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
// look at the examples of the u8g2 library to find the right init sequence for your board!
U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display
#endif
#define FW_STRING "HR460 Arduino FW V0.11 2021, ks@HZB"
// roughly the number of simple loops the ardu can do per second
#define LOOP_WAIT_COUNT 20000
#define NOT_USED_PIN 13
// undef for normal operation
// #define DEBUG
//#define DEBUG
// wavelength drive pin layout and settings
......@@ -326,21 +339,40 @@ WLD wld;
SLIT slitInS,slitInF,slitOutS; // slitOutF not defined/used
MOTORSWITCH mirIn,mirOut,turret;
//int grating[2] = {150,600};
#ifdef OLED
void oledDisplay(){ // display wavelength and grating on a 64x128 OLED display
static char num[8]; // Buffer big enough for 7-character float
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_helvB24_tf);
dtostrf(wld.nmPos(), 6, 2, num);
u8g2.drawStr(0,32,num);
dtostrf(wld.gratlines[turret.pos], 6, 0, num);
u8g2.drawStr(0,64,"Gr");
u8g2.drawStr(40,64,num);
} while ( u8g2.nextPage() );
}
#endif
void setup()
{
long x;
cmdString.reserve(200);
Serial.begin(9600); // we could probably use a higher rate here without decreasing the performance of the rest
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
#ifdef OLED
u8g2.begin();
#endif
wld.init();
x = wld.findLimit();
#ifdef DEBUG
......@@ -350,25 +382,27 @@ void setup()
Serial.println("BOOT ERROR - could not find LIMIT switch");
}
else {
if( reporting )Serial.println("wavelength drive initialized");
if( reporting )Serial.println("wavelength drive init");
// find 0 for the closed slit..
slitInF.init(SLIT_IN_F_POS,SLIT_IN_F_DIR,SLIT_IN_F_OFFSET,SLIT_DO_ZERO_ON_INIT);
if( reporting )Serial.println("Entrance SLIT Front initialized");
if( reporting )Serial.println("Entr SLIT Front init");
slitInS.init(SLIT_IN_S_POS,SLIT_IN_S_DIR,SLIT_IN_S_OFFSET,SLIT_DO_ZERO_ON_INIT);
if( reporting )Serial.println("Entrance SLIT Side initialized");
if( reporting )Serial.println("Entr SLIT Side init");
slitOutS.init(SLIT_OUT_S_POS,SLIT_OUT_S_DIR,SLIT_OUT_S_OFFSET,SLIT_DO_ZERO_ON_INIT);
if( reporting )Serial.println("Exit SLIT Side initialized");
if( reporting )Serial.println("Exit SLIT Side init");
mirIn.init(MIRROR_IN_1,MIRROR_IN_2,MIRROR_WAIT_MS);
if( reporting )Serial.println("Entrance Mirror initialized");
if( reporting )Serial.println("Entr Mir init");
mirOut.init(MIRROR_OUT_1,MIRROR_OUT_2,MIRROR_WAIT_MS);
if( reporting )Serial.println("Exit Mirror initialized");
if( reporting )Serial.println("Exit Mir init");
turret.init(TURRET_1,TURRET_2,TURRET_WAIT_MS);
if( reporting )Serial.println("Turret initialized");
Serial.print("BOOT SUCCESS - found endswitch position at pos = ");
if( reporting )Serial.println("Turret init");
Serial.print("BOOT SUCCESS: endswitch at pos=");
Serial.println(x);
initSuccess = true;
}
}
}
......@@ -379,10 +413,16 @@ void loop() // THE main loop
wld.run(); // this is what actually drives the grating motor...
ctr++;
if( ((ctr)% LOOP_WAIT_COUNT) == 0 && reporting!=0){
Serial.print(wld._pos());
Serial.print(" , ");
Serial.println(wld.nmPos());
if( ((ctr)% LOOP_WAIT_COUNT) == 0 ){
if( reporting ){
Serial.print(wld._pos());
Serial.print(" , ");
Serial.println(wld.nmPos());
}
#ifdef OLED
if( !wld.moving() )oledDisplay();
//oledDisplay();
#endif
};
dispatchCmd(); // something to do?
......
Supports Markdown
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