Melexis SMBus IR Thermometer - NFI

I have the Freeduino am I right to use analogue pins 4 and 5 for the melexis?

My setup:

Pin 1 on MLX (SCC) connect to ANALOG pin 5 on Freeduino
Pin 2 on MLX (SDA) connect to ANALOG pin 4 on Freeduino
Pin 3 on MLX (VDD) connect to 3.3V on Freeduino
Pin 4 on MLX (VSS) connect to GROUND on Freeduino

Im getting this error:

Stepper_Easy_Driver_1_7_With_Cloud_detector_zip.cpp:7:23: error: i2cmaster.h: No such file or directory
Stepper_Easy_Driver_1_7_With_Cloud_detector_zip.cpp: In function 'long int readMLXtemperature(int)':
Stepper_Easy_Driver_1_7_With_Cloud_detector_zip:345: error: 'i2c_init' was not declared in this scope
Stepper_Easy_Driver_1_7_With_Cloud_detector_zip:346: error: 'I2C_WRITE' was not declared in this scope
Stepper_Easy_Driver_1_7_With_Cloud_detector_zip:346: error: 'i2c_start_wait' was not declared in this scope
Stepper_Easy_Driver_1_7_With_Cloud_detector_zip:347: error: 'i2c_write' was not declared in this scope
Stepper_Easy_Driver_1_7_With_Cloud_detector_zip:347: error: 'i2c_write' was not declared in this scope
Stepper_Easy_Driver_1_7_With_Cloud_detector_zip:349: error: 'I2C_READ' was not declared in this scope
Stepper_Easy_Driver_1_7_With_Cloud_detector_zip:349: error: 'i2c_rep_start' was not declared in this scope
Stepper_Easy_Driver_1_7_With_Cloud_detector_zip:350: error: 'i2c_readAck' was not declared in this scope
Stepper_Easy_Driver_1_7_With_Cloud_detector_zip:352: error: 'i2c_readNak' was not declared in this scope
Stepper_Easy_Driver_1_7_With_Cloud_detector_zip:353: error: 'i2c_stop' was not declared in this scope

I have the ic2mater files in the correct directory and renamed twimaster.c to twimaster.cpp

Anyone help please :slight_smile:

Here's the sketch Im using

//START OF FOCUS CONTROL INITIALISE
// include the library code:
#include <LiquidCrystal.h>
#include <Stepper.h>
#include <Servo.h>
#include <i2cmaster.h>

//Start Serial comms definitions:- arrays used for storage of strings and the detection of a string
#define MAX_COMMAND_LEN (5)
#define MAX_PARAMETER_LEN (6)
#define COMMAND_TABLE_SIZE (10)
#define TO_UPPER(x) (((x >= 'a') && (x <= 'z')) ? ((x) - ('a' - 'A')) : (x))
#define SERVO_PIN 19
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int sensorPin = 0; // select the input pin for the LCD buttons
int sensorValue = 0; // variable to store the value coming from the LCD

//Stepper.h pin definitions (incorrect?)
int Pin0 = 33; //Stepper Motor Driver Pin 1
int Pin1 = 35; //Stepper Motor Driver Pin 2
int Pin2 = 37; //Stepper Motor Driver Pin 3
int Pin3 = 39; //Stepper Motor Driver Pin 4

//Easy Driver
int dirPin = 51; // Easy Driver Direction Output Pin
int stepperPin = 53; // EasyDriver Stepper Step Output Pin
int ms1 = 26; //Easy Driver Microstepping output
int ms2 = 28; //Easy Driver microstepping output

// Focus control Variable definition
int motorSteps =200; //number if steps for the motor to turn 1 revolution
volatile int NoOfSteps = 1000; //required number of steps to make
volatile long Position = 0; //used to keep track of the current motorposition
volatile int MaxStep = 16384; //define maximum no. of steps, max travel
volatile int SPEED = 5;
volatile byte MotorType = 0; // Motortypes, default is 0, Stepper motor, 1=Servo, 2=DC motor
boolean Direction = true;//True is one way false is other...depends on motor connection
boolean IsMoving = false;
boolean Absolute = true;
volatile int MaxIncrement=16384;//not yet used

//Stepper.h control variables
Stepper myStepper = Stepper(200, 33, 35, 37, 39);
//END OF FOCUS CONTROL INITIALISE

//Cloud Sensor Setup
char st1[30];
long int tpl; //Cloud sensor variable
long int CS_ObjTemp;
long int CS_AmbTemp;

//Serial comms setup
char incomingByte = 0; // serial in data byte
byte serialValue = 0;
boolean usingSerial = true; // set to false to have the buttons control everything
char gCommandBuffer[MAX_COMMAND_LEN + 1];
char gParamBuffer[MAX_PARAMETER_LEN + 1];
long gParamValue;
volatile boolean UPDATE = true;
typedef struct {
char const *name;
void (*function)(void);
}
command_t;

//Set up a command table. when the command "IN" is sent from the PC and this table points it to the subroutine to run
command_t const gCommandTable[COMMAND_TABLE_SIZE] = {
{
"IN1", FocusINFun, }
,
{
"OUT", FocusOUTFun, }
,
{
"STP", FocusSTEPSFun, }
,
{
"SPD", FocusSPEEDFun, }
,
{
"LMT", FocusSLimitFun, }
,
{
"POS", FocusSPositionFun, }
,
{
"MDE", FocusSModeFun, }
,
{
"TYP", FocusSTypeFun, }
,
{
"TMP", CloudGetTempFun, }
,
{
NULL, NULL }
};
//Serial Comms setup end

void setup() {
if(MotorType==1){
Servo myservo;
myservo.attach(SERVO_PIN);
}
pinMode(dirPin, OUTPUT); //Initialise Easydriver output
pinMode(stepperPin, OUTPUT); //Initialise easy driver output
pinMode (ms1, OUTPUT);
pinMode (ms2, OUTPUT);
//START OF FOCUS CONTROL SETUP
lcd.begin(16, 2);
//END OF FOCUS CONTROL SETUP
Serial.begin(19200);// start the serial

PORTC = (1 << PORTC4) | (1 << PORTC5); //enable internal pullup resistors on i2c ports
myStepper.setSpeed(SPEED);
NoOfSteps=1000;
}

void loop() {

int bCommandReady = false;

digitalWrite(ms1, HIGH);
digitalWrite(ms2, HIGH);

//If There is information in the Serial buffer read it in and start the Build command subroutine
if (usingSerial && Serial.available() >= 1) {
// read the incoming byte:
incomingByte = Serial.read();
delay(250);
if (incomingByte == '#') {
/* Build a new command. */
bCommandReady = cliBuildCommand(incomingByte);
}
}
else
{
incomingByte=0;
//Serial.flush();
}

//If there is a command in the buffer then run the process command subroutine
if (bCommandReady == true) {
bCommandReady = false; // reset the command ready flag
cliProcessCommand(); // run the command
}

if (UPDATE){
UPDATE=false;
FocusPrintStepsFun(); //Print the number of steps
FocusPrintPositionFun(); //Print the Position
SerialDATAFun(); // debug mainly, gives detailed information about the current state of the machine

}

}

//***************************************************
//Start of User defined Functions **************
//
**********************************************

//START OF FOCUS CONTROL FUNCTIONS

void FocusPrintStepsFun (void) {//Print the number of steps required on the 1st line of the LCD display
lcd.setCursor(0, 0);
//lcd.clear();
lcd.print("Steps = ");
lcd.print(NoOfSteps);
lcd.print(" ");
}

void EasyDriverStep(boolean dir,int steps){
digitalWrite(dirPin,dir);
delay(100);
for(int i=0;i<steps;i++){
digitalWrite(stepperPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepperPin, LOW);
delayMicroseconds(500);
}
}

void FocusPrintPositionFun (void) {//Print the current position on the second line of the LCD, this is not absolute.
lcd.setCursor(0, 1);
//lcd.clear();
lcd.print("Position = ");
lcd.print(Position);
lcd.print(" ");

}

void FocusINFun (void) {//Move the Stepper IN.
int Steps = 0;

switch (MotorType){
case 0:
//Serial.println("Stepper Focus IN"); // add stepper movement function and call it here
// will need to 'reset' the arduino via serial to invoke the motor code?
// we need to start saving data in eeprom, it will make things much easier.
// will need to use double the amount of eeprom space for the variables
// one set for the user data and 1 set for defaults. Also means we can start to pack
// some flags as bits
break;

case 1:
//Serial.println("Servo Focus IN"); // Call the servo focus in function
break;

case 2:
//Serial.println("DC Focus IN");

break;
}

if (Absolute == false) { //If not Absolute move the number of steps
if ((Position-NoOfSteps)>=0) {
//myStepper.step (NoOfSteps);
EasyDriverStep(true,NoOfSteps);
Position=Position-NoOfSteps;
}
}
else if (NoOfSteps < MaxStep) //Absolute :- work out the number of steps to take based on current position
{
if (NoOfSteps<Position){

Steps=(Position-NoOfSteps);
//myStepper.step (Steps);
EasyDriverStep(true,Steps);
Position=NoOfSteps;
}
else
{
Steps=(NoOfSteps-Position);
//myStepper.step (Steps);
EasyDriverStep(false,Steps);
Position=NoOfSteps;
}
}
// set the update flag so that the new position is displayed
IsMoving=true;
UPDATE=true;
}

void FocusOUTFun (void) {//Move the Stepper OUT.
int Steps = 0;

if (Absolute == false) { //If not Absolute move the number of steps
if ((Position+NoOfSteps)<=MaxStep) {
//myStepper.step (NoOfSteps);
EasyDriverStep(false,NoOfSteps);
Position=Position+NoOfSteps;
}
}
else if (NoOfSteps < MaxStep) //Absolute :- work out the number of steps to take based on current position
{
if (NoOfSteps<Position){

Steps=(Position-NoOfSteps);
//myStepper.step (Steps);
EasyDriverStep(true,Steps);
Position=NoOfSteps;
}
else
{
Steps=(NoOfSteps-Position);
//myStepper.step (Steps);
EasyDriverStep(false,Steps);
Position=NoOfSteps;
}
}
// set the update flag so that the new position is displayed
IsMoving=true;
UPDATE=true;
}

void FocusSTEPSFun (void) {//Set the number of Steps.
NoOfSteps = gParamValue;
// s