Reading MS5535C using Teensy 3.1 problem

Status
Not open for further replies.

igor p

Active member
View attachment MS55xx.hView attachment MS55xx.cppView attachment MS55xx_underwater.ino

Hi, I use atached example with atached library files to read MS5535C pressure sensor. I do not know why but using teensy 3.1 board can not compile the example.

this is the error:

MS55xx_underwater.ino:19:39: warning: character constant too long for its type [enabled by default]
MS55xx_underwater.ino: In function 'void setup()':
MS55xx_underwater.ino:19:47: warning: large integer implicitly truncated to unsigned type [-Woverflow]
C:\Documents and Settings\Igor P\My Documents\Arduino\libraries\MS55xx\MS55xx.cpp:60:18: warning: character constant too long for its type [enabled by default]
if (SensorType=='MS5535'){
^
C:\Documents and Settings\Igor P\My Documents\Arduino\libraries\MS55xx\MS55xx.cpp: In member function 'void MS55xx::update()':
C:\Documents and Settings\Igor P\My Documents\Arduino\libraries\MS55xx\MS55xx.cpp:20:2: error: 'TCCR1B' was not declared in this scope
TCCR1B = (TCCR1B & 0xF8) | 1 ; //generates the MCKL signal
^
C:\Documents and Settings\Igor P\My Documents\Arduino\libraries\MS55xx\MS55xx.cpp: In member function 'void MS55xx::setPressureSensorType(char)':
C:\Documents and Settings\Igor P\My Documents\Arduino\libraries\MS55xx\MS55xx.cpp:69:8: warning: unused variable 'SensorType' [-Wunused-variable]
char SensorType=PressureSensorType;
^
C:\Documents and Settings\Igor P\My Documents\Arduino\libraries\MS55xx\MS55xx.cpp: In member function 'void MS55xx::getCalibrationWord()':
C:\Documents and Settings\Igor P\My Documents\Arduino\libraries\MS55xx\MS55xx.cpp:99:2: error: 'TCCR1B' was not declared in this scope
TCCR1B = (TCCR1B & 0xF8) | 1 ; //generates the MCKL signal
^
Error compiling.

Can someone help please,

Igor P
 
The library and example you have there are 'AVR centric', what this means is that it is written for Atmel 8 bit AVR devices - I've gauged this from the error messages you have posted from trying to compile it for Teensy 3.1 and have not (yet) downloaded any of your attachments.

I had a quick poke around for if anybody has made a library for MS55xx which is compatible with Teensy 3.1 and I could not find it - do not despair tho, if nobody else seems to look closer and say anything (actually) helpful (as opposed what I am posting here) I will try to remember to look back and be as helpful as I really can when I've better opportunity and cleared a few other things I've on my todo list.
 
I have used the Teensy 3.1 to read the MS5637 and MS5611 pressure sensors; I suspect the protocol is similar. You can see the relevant sketches here.
 
I think you are correct, that library was writen for AVR MCU, the problem is in generation of MCLK 32768 hz clock.
Could I simply use analogWrite(22, 32768); for the purpose?
 
Last edited:
Sorry that doesent help... I use SPI for comunucation with MS5535c. The library was adapted for MS5535c and MS5541
 
For the mclk use analog frequency:
Code:
  analogWriteFrequency(MCLK_PIN, 32768);
  analogWrite(kPin_CLK, 128);
 
Hi, thanks for answer,

The MCLK_pin in the code probably should be changed with the pin I use for MCLK generation.
Do I need to put there both commands?
What is that k_Pin_CLK ?is it meant: analogWrite(MCLK_pin,128);
 
Last edited:
Here, I've modified the files for you. Try this copy.

Are these published somewhere? If this works, maybe we could get whereever they're published to update?
 

Attachments

  • MS55xx.cpp
    4.1 KB · Views: 186
  • MS55xx.h
    2.3 KB · Views: 103
  • MS55xx_underwater.ino
    1.1 KB · Views: 112
Here, I've modified the files for you. Try this copy.

Are these published somewhere? If this works, maybe we could get whereever they're published to update?

Hi Paul,

thank you very much for your help. Will try it out as soon as I manage and let you know.

This library was writen by someone else .... it should be writen in files .... I just changed it to cover MA5535C and MS5541 pressure sensors .... this is why it is callec "MS55xx".
And sure agree we could post correction to work with Teensy 3.0 and up.

Thanks again!

Igor P
 
Who wrote this library? Can we get them to update their copy?

below original quote from the .h file of library.
I only changed it to incorporate both MS5535C and MS5541.
It is from arduino forum. Wil try to find out who wrote it.
Or I will post to the original thread on Arduino and post the updated version.

/******************************************************************
* MS5541 Pressure Sensor calwords readout
* This library read your MS5541 sensor using SPI protocol
* Please respect pin wiring:
* MOSI: pin 11 or pin 7 on sensor
* MISO: pin 12 or pin 8 on sensor
* SCK: pin 13 or pin 1 on sensor
* MCLK: pin 9 or pin 6 on sensor

* This library is developed using part of code from another author (called godo on arduino forum), please visit arduino forum for that:
* http://forum.arduino.cc/index.php?topic=67188.0
*
* Author fro original code:
* created August 2011
* by SMStrauch based on application note AN510 from www.intersema.ch (http://www.meas-spec.com/downloads/Using_SPI_Protocol_with_Pressure_Sensor_Modules.pdf),
* and with help of robtillaart and ulrichard. Thanks!
*

*
* Lib version history
* 1.0 first lib created.
*
*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<http://www.gnu.org/licenses/>
*
******************************************************************/
 
Last edited:
Ok, here is original forum with the writer of the library I adapted to both MS5535C and MS5541 sensors .https://forum.arduino.cc/index.php?topic=289503.0
I am noticing autor and posting to his thread the library. The name will remain MS55xx.
Same I am adding it here complete.

Igor P
 

Attachments

  • MS55xx.zip
    4.7 KB · Views: 93
Last edited:
Hi all, I have another problem. The library works fine, I can get all data needed from sensor, but have problem when adding Adafruit 1.8 TFT. I get wrong readings from sensor and the TFT remains black. I did add to code the pressure sensor CS and the tristate buffer.. Anyone know of problems with this combo? If I remove the sensor library and code for reading sensor, I get normal functioning TFT, adding sensor code .... nothing on TFT and false readings.... Removing code for TFT , normal readings from sensor.

Code:
#define sclk 13  // SCLK can also use pin 14
#define mosi 11  // MOSI can also use pin 7
#define cs   10  // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
#define dc   9   //  but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
#define rst  8   // RST can use any pin
#define sdcs 4   // CS for SD card, can use any pin
#define lite 5   // TFT backlite
#define presscs 6 // Pressures sensor cs
#define miso 12 //MISO

#include <MS55xx.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>

#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif

//Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);

//creating the sensor

MS55xx PressSensor;
float airPressure;
float waterPressure=0;

void setup() {
    pinMode(sdcs, INPUT_PULLUP);   
    Serial.begin(9600);     
    pinMode(presscs, OUTPUT);
    digitalWrite(presscs, HIGH);      
    pinMode(5, OUTPUT);
    digitalWrite(5, HIGH);
    pinMode(23, OUTPUT);
    digitalWrite(23, HIGH);
    
    tft.initR(INITR_BLACKTAB); 
    tft.setRotation(tft.getRotation()+1);
    tft.fillScreen(ST7735_BLACK); 
    
    PressSensor.setPressureSensorType(5535);
    //start arduino before diving
    //otherwise a 1.0 bar is used as surface pressure
    digitalWrite(presscs, LOW);
    delay(10);
    PressSensor.update();
    digitalWrite(presscs, HIGH);
    airPressure = PressSensor.getPressureBar();
    if (airPressure > 1.2) {
      airPressure = 1.0;
    }
    tft.fillScreen(ST7735_BLACK);
}

void loop() {
  //Before getting the values you need to update the sensor
  digitalWrite(presscs, LOW);
  delay(10);
  PressSensor.update();
  digitalWrite(presscs, HIGH);
  //get pressure
  waterPressure = PressSensor.getPressureBar() - airPressure;
  Serial.print("Deep (meters): ");
  Serial.println(abs(waterPressure)*10.0,1);
  
  tft.setTextSize(2);
  tft.setCursor(0,0);
  tft.setTextColor(ST7735_GREEN);
  tft.println(abs(waterPressure)*10.0,1);
   
  //get 2nd temperature --> see datasheet for details
  Serial.print("Temperatre 2nd (celsius): ");
  //Serial.println(PressSensor.get2ndTemperatureC());
  
  Serial.println();
  
  delay(2000);
}
 
Last edited:
I just found I need to use
Code:
SPI.setDataMode(SPI_MODE0);
in PressSensor.Update() method as last line to return SPI Mode so that AdafruitST7735 can use SPI normaly and work as expected. I get display functioning normal again.

I added manipulation of CS in the MS55xx library, so that I do not need to handle it in main code. But it does no't help.

The problem that remain is I still can not get correct data from pressure sensor. As soon as use the initializaion of TFT
Code:
tft.initR(INITR_BLACKTAB);
I lose the pressure sensor data.

Can anyone help please?
 
Last edited:
HI Paul

thank you very much for your answer!

I tried to add to my library MS55xx the SPI.beginTransaction() and SPI.endTransaction() commands before, but no better so removed them. Will try to add SPI.beginTransaction() and SPI.endTransaction() to both libraryes - the Adafruit_ST7735 and to MS55xx library in same mode as described in the links you mention. Will let you know hpw it goes.

One more question, is there anything else beside mentioned missing functions in Adafruit_ST7735 that could limit use of SPI to other devices?

Thanks for help!!
 
Last edited:
View attachment Adafruit_ST7735.cppView attachment MS55xx.cpp

Hi, I added the suggested SPI.beginTransaction() and SPI.endTransaction() in Adafruit_ST7735 library and MS55xx library, but no better. Still same result, have display working, but the data from pressure sensor not correct. More testing toomorrow.
I am attaching the libraryes and would love to see if someone can check if I correctely added SPI.beginTransaction() and SPI.endTransaction(). Added only in Teensy3.0/3.1 definition part.
 
Last edited:
2316
4937
370
226
2153
56
Pressure (mBar): 85646.0
Temperatre 2nd (celsius): 226.57


this are the values I get from sensor. The first 6 are koecifients I read from sensor before TFT initialisation and other are calculated from data read after the initialisation of TFT, so false.
Do not know what to do any more.

Here is the Adafruit_ST7735 I enclosed all SPI transactions in suggested SPI.beginTransaction() and SPI.endTransaction(). Same I add the last MS55xx library.
 

Attachments

  • Adafruit_ST7735.cpp
    29 KB · Views: 126
  • MS55xx.cpp
    5.8 KB · Views: 96
I tryed to change library to use parameter passing for sensors cs and mclk, but noticed compiler does not see some changes. So will transcribe the complete library to see if any better.

Paul, hope yo find some time to look inlast files I posted to see if they are consistent....

Thanks
 
Transcribed from scratch the library, now rtansfer sc and mclk for sensor as parameters, but no change. as soon as initialized tft, I lose sensor data.
I added everywhere used SPI the SPI.beginTransaction() and SPI.endTransaction(). The only thing I am not sure of is Adafruit_ST7735 library ... if it has correctely implemented the enclosure for SPI transactions.
 
Got answer from Adafruit to use some commands for saving SPCR register, but Paul thinks it is not good to use, so am not. The problem remain and I do not know how to solve this enigma... I did everything suggested, but no better.

Please help!

Igor P
 
In the linked sketch above (post #13) you have dc from the tft connected to pin 9 from the Teensy. In the MS55xx.cpp the MCLK output is hardcoded for pin 9.
 
Adafruit updated their library per last standards in SPI communication and now I finaly have a solution in my hands. Will post links to the thread with updated ST7735 library and new version of MS55xx library updated to same standard.

Thanks to all that tried to be helpful!!
Specialy to Paul that involved himselfe in the Adafruit thread to convince them to update the library. Am waiting for definitive version and than I will post.

Thanks again Igor P
 
Last edited:
Testing extensively the Adafruit updated library non definitive, the results are not good. The screen is updated very slowly and makes running software slow on teensy.
Adafruit did not jet made the definitive version, so still waiting on it. Unfortunately even the updated version (the one from time of previous message) is not satisfactory working. it makes so slow running the software that normal Bounce() or similar aproaches can not be used succesfuly to detect momentary switches when pressed. Anyone got a suggestion to enable use of Teensyduino Adafruit_ST7735 library to work with MS55xx library?
The Teensyduino's library is fast and works verywell, but unfortunately does not work with the MS55xx library... or I am too nob to enable it somehow.

EDIT:

managed to run SPI faster with the TFT .... the settings for SCLK needs to be 25MHz. some other tweeks and it will be ok. I did slightely change Adafruits updated library and it is now more in line with Arduino SPI directions. Still fewe things to fix and it will be ok. Same with the MS55xx library and everything will be as it should.

Later when finished libraryes will be posted here.
 
Last edited:
Status
Not open for further replies.
Back
Top