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


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...
#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:
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
// 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
#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
do {
dtostrf(wld.nmPos(), 6, 2, num);
dtostrf(wld.gratlines[turret.pos], 6, 0, num);
} while ( u8g2.nextPage() );
void setup()
long x;
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
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..
if( reporting )Serial.println("Entrance SLIT Front initialized");
if( reporting )Serial.println("Entr SLIT Front init");
if( reporting )Serial.println("Entrance SLIT Side initialized");
if( reporting )Serial.println("Entr SLIT Side init");
if( reporting )Serial.println("Exit SLIT Side initialized");
if( reporting )Serial.println("Exit SLIT Side init");
if( reporting )Serial.println("Entrance Mirror initialized");
if( reporting )Serial.println("Entr Mir init");
if( reporting )Serial.println("Exit Mirror initialized");
if( reporting )Serial.println("Exit Mir init");
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=");
initSuccess = true;
......@@ -379,10 +413,16 @@ void loop() // THE main loop; // this is what actually drives the grating motor...
if( ((ctr)% LOOP_WAIT_COUNT) == 0 && reporting!=0){
Serial.print(" , ");
if( ((ctr)% LOOP_WAIT_COUNT) == 0 ){
if( reporting ){
Serial.print(" , ");
#ifdef OLED
if( !wld.moving() )oledDisplay();
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