MMA8451 Accelerometer and Tmp006

Hi I’m trying to read data from Adafruit MMA8451 accelerometer and Adafruit Tmp006 together. I can work either on their own without changing waiting as I have them wired in parallel correct to serial clock and serial data lines . Unfortunately after days of research I still can’t combine the 2 sensors in one programme . Any advice or help would be greatly appreciated thanks

We can't see:

a) your code
b) your schematic

And please don't hijack unrelated topics.

Acceleromotor code

/**************************************************************************/
/*!
@file Adafruit_MMA8451.h
@author K. Townsend (Adafruit Industries)
@license BSD (see license.txt)

This is an example for the Adafruit MMA8451 Accel breakout board
----> https://www.adafruit.com/products/2019

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

@section HISTORY

v1.0 - First release
*/
/**************************************************************************/

#include <Wire.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>

Adafruit_MMA8451 mma = Adafruit_MMA8451();

void setup(void) {
Serial.begin(9600);

Serial.println(“Adafruit MMA8451 test!”);

if (! mma.begin()) {
Serial.println(“Couldnt start”);
while (1);
}
Serial.println(“MMA8451 found!”);

mma.setRange(MMA8451_RANGE_2_G);

Serial.print("Range = "); Serial.print(2 << mma.getRange());
Serial.println(“G”);

}

void loop() {
// Read the ‘raw’ data in 14-bit counts
mma.read();
Serial.print(“X:\t”); Serial.print(mma.x);
Serial.print("\tY:\t"); Serial.print(mma.y);
Serial.print("\tZ:\t"); Serial.print(mma.z);
Serial.println();

/* Get a new sensor event */
sensors_event_t event;
mma.getEvent(&event);

/* Display the results (acceleration is measured in m/s^2) */
Serial.print(“X: \t”); Serial.print(event.acceleration.x); Serial.print("\t");
Serial.print(“Y: \t”); Serial.print(event.acceleration.y); Serial.print("\t");
Serial.print(“Z: \t”); Serial.print(event.acceleration.z); Serial.print("\t");
Serial.println("m/s^2 ");

/* Get the orientation of the sensor */
uint8_t o = mma.getOrientation();

switch (o) {
case MMA8451_PL_PUF:
Serial.println(“Portrait Up Front”);
break;
case MMA8451_PL_PUB:
Serial.println(“Portrait Up Back”);
break;
case MMA8451_PL_PDF:
Serial.println(“Portrait Down Front”);
break;
case MMA8451_PL_PDB:
Serial.println(“Portrait Down Back”);
break;
case MMA8451_PL_LRF:
Serial.println(“Landscape Right Front”);
break;
case MMA8451_PL_LRB:
Serial.println(“Landscape Right Back”);
break;
case MMA8451_PL_LLF:
Serial.println(“Landscape Left Front”);
break;
case MMA8451_PL_LLB:
Serial.println(“Landscape Left Back”);
break;
}
Serial.println();
delay(500);

}

Temperature Sensor Code

#include <Adafruit_Sensor.h>

/***************************************************
This is an example for the TMP006 Contact-less Infrared Thermopile Sensor

Designed specifically to work with the Adafruit TMP006 Breakout
----> https://www.adafruit.com/products/1296

These displays use I2C to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include “Adafruit_TMP006.h”

// Connect VCC to +3V (its a quieter supply than the 5V supply on an Arduino
// Gnd → Gnd
// SCL connects to the I2C clock pin. On newer boards this is labeled with SCL
// otherwise, on the Uno, this is A5 on the Mega it is 21 and on the Leonardo/Micro digital 3
// SDA connects to the I2C data pin. On newer boards this is labeled with SDA
// otherwise, on the Uno, this is A4 on the Mega it is 20 and on the Leonardo/Micro digital 2

Adafruit_TMP006 tmp006;
//Adafruit_TMP006 tmp006(0x41); // start with a diferent i2c address!

void setup() {
Serial.begin(9600);
Serial.println(“Adafruit TMP006 example”);

// you can also use tmp006.begin(TMP006_CFG_1SAMPLE) or 2SAMPLE/4SAMPLE/8SAMPLE to have
// lower precision, higher rate sampling. default is TMP006_CFG_16SAMPLE which takes
// 4 seconds per reading (16 samples)
if (! tmp006.begin()) {
Serial.println(“No sensor found”);
while (1);
}

Serial.println(“Send s to enter sleep mode, or w to wake up. Measurements are not updated while asleep!”);
}

void loop() {
// Check for sleep/wake command.
while (Serial.available() > 0) {
char c = Serial.read();
if (c == ‘w’) {
Serial.println(“Waking up!”);
tmp006.wake();
}
else if (c == ‘s’) {
Serial.println(“Going to sleep!”);
tmp006.sleep();
}
}

// Grab temperature measurements and print them.
float objt = tmp006.readObjTempC();
//Serial.print(“Object Temperature: “);
Serial.print(objt);
Serial.print(”\t”);
//Serial.println("*C");
float diet = tmp006.readDieTempC();
//Serial.print(“Die Temperature: “);
Serial.println(diet);
//Serial.println(”*C”);

delay(400); // 4 seconds per reading for 16 samples per reading
}

dont have image of schematic sorry but they are wired in parallel and either programme will work without changing the wiring .

Where's the combined code?

Please remember to use code tags when posting code

/**************************************************************************/
/*!
    @file     Adafruit_MMA8451.h
    @author   K. Townsend (Adafruit Industries)
    @license  BSD (see license.txt)

    This is an example for the Adafruit MMA8451 Accel breakout board
    ----> https://www.adafruit.com/products/2019

    Adafruit invests time and resources providing this open source code,
    please support Adafruit and open-source hardware by purchasing
    products from Adafruit!

    @section  HISTORY

    v1.0  - First release
*/
/**************************************************************************/

#include <Wire.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TMP006.h"



const int Adafruit_MMA8451 = 29;
const int Adafruit_TMP006  = 64;
//Adafruit_TMP006 tmp006(0x41);  // start with a diferent i2c address!
void setup(void) {
  Serial.begin(9600);
  Serial.println("Adafruit TMP006 example");
  Serial.println();
  Serial.println("Adafruit MMA8451 test!");

    if (!TMP006.begin(64)) {
    Serial.println("No sensor found");
    while (1);
  }
  Serial.println();
  Serial.println("Send s to enter sleep mode, or w to wake up.  Measurements are not updated while asleep!");

 
 if (! mma.begin(29)) { 
 
    Serial.println("Couldnt start");
    while (1);
  }
  Serial.println();
  Serial.println("MMA8451 found!");
  
  mma.setRange(MMA8451_RANGE_2_G);
  
  Serial.print("Range = "); Serial.print(2 << mma.getRange());  
  Serial.println("G");
  
}

void loop(){

 while (Serial.available() > 0) {
    char c = Serial.read();
    if (c == 'w') {
      Serial.println("Waking up!");
      64.wake();
    }
    else if (c == 's') {
      Serial.println("Going to sleep!");
      64.sleep();
    }
  }
{
  // Grab temperature measurements and print them.
  float objt = 64.readObjTempC();
  //Serial.print("Object Temperature: ");
  Serial.print(objt);
  Serial.print("\t");
  //Serial.println("*C");
  float diet = 64.readDieTempC();
  //Serial.print("Die Temperature: "); 
  Serial.println(diet);
  //Serial.println("*C");
  Serial.println(); 
  delay(400); // 4 seconds per reading for 16 samples per reading
}
 {
  // Read the 'raw' data in 14-bit counts
  mma.read();
  Serial.print("X:\t"); Serial.print(mma.x); 
  Serial.print("\tY:\t"); Serial.print(mma.y); 
  Serial.print("\tZ:\t"); Serial.print(mma.z); 
  Serial.println();

  /* Get a new sensor event */ 
  sensors_event_t event; 
  mma.getEvent(&event);

  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t");
  Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t");
  Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
  Serial.println("m/s^2 ");
  
  /* Get the orientation of the sensor */
  uint8_t o = mma.getOrientation(); 
  
  switch (o) {
    case MMA8451_PL_PUF: 
      Serial.println("Portrait Up Front");
      break;
    case MMA8451_PL_PUB: 
      Serial.println("Portrait Up Back");
      break;    
    case MMA8451_PL_PDF: 
      Serial.println("Portrait Down Front");
      break;
    case MMA8451_PL_PDB: 
      Serial.println("Portrait Down Back");
      break;
    case MMA8451_PL_LRF: 
      Serial.println("Landscape Right Front");
      break;[code]
    case MMA8451_PL_LRB: 
      Serial.println("Landscape Right Back");
      break;
    case MMA8451_PL_LLF: 
      Serial.println("Landscape Left Front");
      break;
    case MMA8451_PL_LLB: 
      Serial.println("Landscape Left Back");
      break;
    }
  Serial.println();
  delay(500);
  
}
}

:o

#include <Wire.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TMP006.h"

// Connect VCC to +3V (its a quieter supply than the 5V supply on an Arduino
// Gnd -> Gnd
// SCL connects to the I2C clock pin. On newer boards this is labeled with SCL
// otherwise, on the Uno, this is A5 on the Mega it is 21 and on the Leonardo/Micro digital 3
// SDA connects to the I2C data pin. On newer boards this is labeled with SDA
// otherwise, on the Uno, this is A4 on the Mega it is 20 and on the Leonardo/Micro digital 2

 
int Adafruit_TMP006;
//Adafruit_TMP006 tmp006(0x41);  // start with a diferent i2c address!
int Adafruit_MMA8451 = mma;


void setup(void) {
  Serial.begin(9600);
  Wire.beginTransmission(Adafruit_TMP006); //Send a request to begin communication with the device at the specified address

Wire.write(0); //Sends a bit asking for register 0, the data register of the TC74 sensor

Wire.endTransmission(); //this ends transmission of data from the arduino to the temperature sensor

//this now reads the temperature from the tmp006 sensor
Wire.requestFrom(Adafruit_TMP006, 1);//this requests 1 byte from the specified address

while(Wire.available() == 0);

int celsius1= Wire.read();



Serial.print("Temperature sensor 1:");
Serial.print(celsius1);
Serial.print("degrees celsius ");
Serial.println();

delay(2000);

Serial.begin(9600);
  
  Serial.println("Adafruit MMA8451 test!");
  

  if (! mma.begin()) {
    Serial.println("Couldnt start");
    while (1);
  }
  Serial.println("MMA8451 found!");
  
  mma.setRange(MMA8451_RANGE_2_G);
  
  Serial.print("Range = "); Serial.print(2 << mma.getRange());  
  Serial.println("G");
  
}

void loop() {
Wire.beginTransmission(Adafruit_MMA8451); //Send a request to begin communication with the device at the specified address

Wire.write(0); //Sends a bit asking for register 0, the data register of the TC74 sensor

Wire.endTransmission(); //this ends transmission of data from the arduino to the temperature sensor

//this now reads the temperature from the TC74 sensor
Wire.requestFrom(Adafruit_MMA8451, 1);//this requests 1 byte from the specified address

while(Wire.available() == 0);
int  // Read the 'raw' data in 14-bit counts
  mma.read();
  Serial.print("X:\t"); Serial.print(mma.x); 
  Serial.print("\tY:\t"); Serial.print(mma.y); 
  Serial.print("\tZ:\t"); Serial.print(mma.z); 
  Serial.println();

  /* Get a new sensor event */ 
  sensors_event_t event; 
  mma.getEvent(&event);

  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t");
  Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t");
  Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
  Serial.println("m/s^2 ");
  
  /* Get the orientation of the sensor */
  uint8_t o = mma.getOrientation();
  
  switch (o) {
    case MMA8451_PL_PUF: 
      Serial.println("Portrait Up Front");
      break;
    case MMA8451_PL_PUB: 
      Serial.println("Portrait Up Back");
      break;    
    case MMA8451_PL_PDF: 
      Serial.println("Portrait Down Front");
      break;
    case MMA8451_PL_PDB: 
      Serial.println("Portrait Down Back");
      break;
    case MMA8451_PL_LRF: 
      Serial.println("Landscape Right Front");
      break;
    case MMA8451_PL_LRB: 
      Serial.println("Landscape Right Back");
      break;
    case MMA8451_PL_LLF: 
      Serial.println("Landscape Left Front");
      break;
    case MMA8451_PL_LLB: 
      Serial.println("Landscape Left Back");
      break;
    }
  Serial.println();

delay(2000);
} 






}