Permalink
Browse files

Fixing several #ifdef issues concerning HAS_HEATED_PLATFORM and addin…

…g optional support for I2C-LC-Display

In order to disable the HAS_HEATED_PLATFORM code by setting the #define to 0 (instead of commenting it out), several #ifdef resp. #ifndef statements needed to be changed to #if resp. #if ! statements.

The optional I2C-LC-Display support can be enabled by setting the #define HAS_I2C_LCD to 1 (in Configuration.h). In case HAS_I2C_LCD is enabled, we have a low memory problem. To solve this, the currently unused EEPROM and SERVO handling is automatically disabled when HAS_I2C_LCD is enabled (and vice versa).

The I2C_LCD support within the extruder controller currently supports basic display of states handled by the controller:
- Extruder temperature (current & target)
- Platform temperature (current & target, if enabled/available)
- Extruder-Motor ("Extruding..."/"Idle")
  • Loading branch information...
zaggo committed Nov 27, 2009
1 parent 6e2c45f commit d72b0c693421b79388b5474079d5b0c9dc089ae7
@@ -20,14 +20,21 @@
#error Oops! Make sure you have 'Arduino' selected from the boards menu.
#endif
+#include "Configuration.h"
+
//include some basic libraries.
#include <WProgram.h>
-#include <Servo.h>
#include <stdint.h>
-#include <EEPROM.h>
#include <SimplePacket.h>
-#include "Configuration.h"
+#if HAS_I2C_LCD
+ #include <Wire.h>
+ #include "I2cLCD.h"
+#else // ...we have to save memory, so no EEPROM and Servo in case of I2C_LCD
+ #include <EEPROM.h>
+ #include <Servo.h>
+#endif
+
#include "Datatypes.h"
#include "Variables.h"
#include "PacketProcessor.h"
@@ -44,9 +51,13 @@ void setup()
init_serial(); //dont want to re-initialize serial!
initialize();
+#if HAS_I2C_LCD
+ lcd.initialize();
+#endif
+
//this is a simple text string that identifies us.
- //Serial.print("R3G Slave v");
- //Serial.println(FIRMWARE_VERSION, DEC);
+ // Serial.print("R3G Slave v");
+ // Serial.println(FIRMWARE_VERSION, DEC);
}
//this function takes us back to our default state.
@@ -81,10 +92,14 @@ void loop()
{
extruder_heater.manage_temperature();
-#ifdef HAS_HEATED_BUILD_PLATFORM
+#if HAS_HEATED_BUILD_PLATFORM
platform_heater.manage_temperature();
#endif
+#if HAS_I2C_LCD
+ lcd.updateTempDisplay();
+#endif
+
}
}
@@ -35,10 +35,19 @@
* Is there a heated build platform?
****************************************************************************************/
-#define HAS_HEATED_BUILD_PLATFORM 1
+#define HAS_HEATED_BUILD_PLATFORM 0
// Define the default temperature for the heated build platform
#define DEFAULT_PLATFORM_TEMPERATURE 0
+/****************************************************************************************
+ * Is there a LC-Display?
+ * If yes, we have to save space. Thus if HAS_I2C_LCD==1, EEPROM and SERVO handling are
+ * automatically disabled
+ ****************************************************************************************/
+
+#define HAS_I2C_LCD 0
+#define TEMP_LCD_UPDATE_INTERVAL 1500
+
/****************************************************************************************
* Define the PID behavior for the heater
****************************************************************************************/
@@ -6,6 +6,10 @@
#include "PacketProcessor.h"
#include "ThermistorTable.h"
+#if HAS_I2C_LCD
+ #include "I2cLCD.h"
+#endif
+
// Yep, this is actually -*- c++ -*-
void init_extruder()
{
@@ -23,9 +27,11 @@ void init_extruder()
motor2_target_rpm = 0;
motor2_current_rpm = 0;
- //free up 9/10
+#if !HAS_I2C_LCD // We have to save memory in case of HAS_I2C_LCD
+// //free up 9/10
servo1.detach();
servo2.detach();
+#endif
//init our PID stuff.
speed_error = 0;
@@ -41,7 +47,7 @@ void init_extruder()
extruder_heater.init(EXTRUDER_THERMISTOR_PIN, EXTRUDER_HEATER_PIN, false);
#endif
-#ifdef HAS_HEATED_BUILD_PLATFORM
+#if HAS_HEATED_BUILD_PLATFORM
#ifdef PLATFORM_THERMOCOUPLER_PIN
platform_heater.init(PLATFORM_THERMOCOUPLER_PIN, PLATFORM_HEATER_PIN, true);
#else
@@ -75,7 +81,7 @@ void init_extruder()
//setup our various accessory pins.
pinMode(EXTRUDER_HEATER_PIN, OUTPUT);
pinMode(FAN_PIN, OUTPUT);
-#ifdef HAS_HEATED_BUILD_PLATFORM
+#if HAS_HEATED_BUILD_PLATFORM
pinMode(PLATFORM_HEATER_PIN, OUTPUT);
#else
pinMode(VALVE_PIN, OUTPUT);
@@ -84,7 +90,7 @@ void init_extruder()
//turn them all off
digitalWrite(EXTRUDER_HEATER_PIN, LOW);
digitalWrite(FAN_PIN, LOW);
-#ifdef HAS_HEATED_BUILD_PLATFORM
+#if HAS_HEATED_BUILD_PLATFORM
digitalWrite(PLATFORM_HEATER_PIN, LOW);
#else
digitalWrite(VALVE_PIN, LOW);
@@ -97,8 +103,8 @@ void init_extruder()
//default to zero.
extruder_heater.set_target_temperature(0);
-#ifdef HAS_HEATED_BUILD_PLATFORM
- //default build platform to 60 C
+#if HAS_HEATED_BUILD_PLATFORM
+ //default build platform to default value
platform_heater.set_target_temperature(DEFAULT_PLATFORM_TEMPERATURE);
#endif
@@ -129,6 +135,9 @@ else
void enable_motor_1()
{
+#if HAS_I2C_LCD
+ lcd.updateStatus("Extruding...");
+#endif
if (motor1_control == MC_PWM)
{
//nuke any previous reversals.
@@ -157,6 +166,9 @@ void enable_motor_1()
void disable_motor_1()
{
+#if HAS_I2C_LCD
+ lcd.updateStatus("Idle");
+#endif
if (motor1_control == MC_PWM)
{
analogWrite(MOTOR_1_SPEED_PIN, 0);
@@ -282,7 +294,7 @@ void disable_fan()
digitalWrite(FAN_PIN, LOW);
}
-#ifndef HAS_HEATED_BUILD_PLATFORM
+#if !HAS_HEATED_BUILD_PLATFORM
void open_valve()
{
digitalWrite(VALVE_PIN, HIGH);
@@ -19,7 +19,7 @@ void disable_motor_2();
void enable_fan();
void disable_fan();
-#ifndef HAS_HEATED_BUILD_PLATFORM
+#if !HAS_HEATED_BUILD_PLATFORM
void open_valve();
void close_valve();
#endif
@@ -31,6 +31,11 @@ void Heater::set_target_temperature(int temp)
max_temperature = (int)((float)temp * 1.1);
}
+int Heater::get_target_temperature()
+{
+ return target_temperature;
+}
+
bool Heater::hasReachedTargetTemperature()
{
return (current_temperature > (int)(target_temperature * 0.95));
@@ -9,7 +9,7 @@ class Heater
bool usesThermocoupler;
int inputPin;
int outputPin;
-
+
int current_temperature;
int target_temperature;
int max_temperature;
@@ -38,7 +38,10 @@ class Heater
void init(int inPin, int outPin, bool isThermocoupler);
int get_current_temperature();
+
void set_target_temperature(int temp);
+ int get_target_temperature();
+
bool hasReachedTargetTemperature();
void manage_temperature();
@@ -0,0 +1,134 @@
+#include "Configuration.h"
+#include <WProgram.h>
+#include "I2cLCD.h"
+#include "Version.h"
+#include "Heater.h"
+#include "Variables.h"
+
+void I2cLCD::initialize()
+{
+ last_lcd_update_time = 0;
+
+ // Setup I2C hardware
+ Wire.begin();
+
+ // Switch on LCD
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_DisplayON_OFF);
+ Wire.send(kI2C_DisplayON); // On, no Cursor, no Blink
+ Wire.endTransmission();
+
+ // Clear the Display
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_ClrDisplay);
+ Wire.endTransmission();
+
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_WriteString);
+ Wire.send("Welcome to MakerBot");
+ Wire.endTransmission();
+
+ setCursorRC(1,0);
+ char fwVersion[32];
+ sprintf(fwVersion,"Extruder FW v%d.%d%s",FIRMWARE_VERSION/100,FIRMWARE_VERSION%100, FIRMWARE_BUILD_NUMBER_STRING);
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_WriteString);
+ Wire.send(fwVersion);
+ Wire.endTransmission();
+
+ delay(3000);
+
+ // Setup the basic screen
+
+ // Clear the Display
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_ClrDisplay);
+ Wire.endTransmission();
+
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_WriteString);
+ Wire.send("Extruder:");
+ Wire.endTransmission();
+
+#if HAS_HEATED_BUILD_PLATFORM
+ setCursorRC(1,0);
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_WriteString);
+ Wire.send("Platform:");
+ Wire.endTransmission();
+#endif
+
+ updateStatus("Idle");
+
+ sprintf(fwVersion,"v%d.%d%s",FIRMWARE_VERSION/100,FIRMWARE_VERSION%100, FIRMWARE_BUILD_NUMBER_STRING);
+ setCursorRC(3,20-strlen(fwVersion));
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_WriteString);
+ Wire.send(fwVersion);
+ Wire.endTransmission();
+}
+
+void I2cLCD::setCursorRC(uint8_t row, uint8_t column)
+{
+ if(row<4 && column<20)
+ {
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_SetCursor);
+ switch(row)
+ {
+ case 0: Wire.send(kLCD_DDA_Line0+column); break;
+ case 1: Wire.send(kLCD_DDA_Line1+column); break;
+ case 2: Wire.send(kLCD_DDA_Line2+column); break;
+ case 3: Wire.send(kLCD_DDA_Line3+column); break;
+ }
+
+ Wire.endTransmission();
+ }
+}
+
+void I2cLCD::updateTemp(int line, int current, int target)
+{
+ setCursorRC(line, 9);
+ char tempString[12];
+ sprintf(tempString,"%3d%cC%c%3d%cC", current, 0xdf, 0x7e, target, 0xdf);
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_WriteString);
+ Wire.send(tempString);
+ Wire.endTransmission();
+}
+
+void I2cLCD::updateStatus(char* status)
+{
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_Delete);
+ Wire.send((uint8_t)3);
+ Wire.send((uint8_t)1);
+ Wire.send((uint8_t)20);
+ Wire.endTransmission();
+
+ setCursorRC(2, 0);
+ Wire.beginTransmission(kI2C_LCD_SLAVE_ADR);
+ Wire.send(kI2C_WriteString);
+ Wire.send(status);
+ Wire.endTransmission();
+}
+
+void I2cLCD::updateTempDisplay()
+{
+ int dt;
+ unsigned long time;
+
+ // ignoring millis rollover for now
+ time = millis();
+
+ dt = time - last_lcd_update_time;
+ if (dt > TEMP_LCD_UPDATE_INTERVAL)
+ {
+ last_lcd_update_time = time;
+
+ updateTemp(0, extruder_heater.get_current_temperature(), extruder_heater.get_target_temperature());
+#if HAS_HEATED_BUILD_PLATFORM
+ updateTemp(1, platform_heater.get_current_temperature(), platform_heater.get_target_temperature());
+#endif
+ }
+}
Oops, something went wrong.

0 comments on commit d72b0c6

Please sign in to comment.