Home › Forums › Environmental Sensors › Yosemite library cant be found! › Reply To: Yosemite library cant be found!
2020-01-16 at 7:44 AM
#13657
-
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277/*****************************************************************************GetValues.inoThis prints basic meta-data about a sensor to the first serial port and thenbegins taking measurements from the sensor.The sensor model and address can easily be modified to use this sketch with anyYosemitech modbus sensor.*****************************************************************************/// ---------------------------------------------------------------------------// Include the base required libraries// ---------------------------------------------------------------------------#include <Arduino.h>#include <SoftwareSerial.h>#include <Wire.h> // For the I2C for the OLED display#include <AMAdafruit_GFX.h> // For the OLED display#include <SDL_Arduino_SSD1306.h> // For the OLED display#include <YosemitechModbus.h>// ---------------------------------------------------------------------------// Set up the sensor specific information// ie, pin locations, addresses, calibrations and related settings// ---------------------------------------------------------------------------// Define the sensor typeyosemitechModel model = Y502; // The sensor model number// Define the sensor's modbus addressbyte modbusAddress = 0x01; // The sensor's modbus address, or SlaveID// Yosemitech ships sensors with a default ID of 0x01.// Define pin number variablesconst int PwrPin = D6; // The pin sending power to the sensor *AND* RS485 adapterconst int DEREPin = -1; // The pin controlling Recieve Enable and Driver Enable// on the RS485 adapter, if applicable (else, -1)// Setting HIGH enables the driver (arduino) to send text// Setting LOW enables the receiver (sensor) to send textconst int SSRxPin = D6 ; // Recieve pin for software serial (Rx on RS485 adapter)const int SSTxPin = D5; // Send pin for software serial (Tx on RS485 adapter)// Construct software serial object for ModbusSoftwareSerial modbusSerial(SSRxPin, SSTxPin);// Construct the Yosemitech modbus instanceyosemitech sensor;bool success;// Set up the OLED displaySDL_Arduino_SSD1306 display(-1); // using I2C and not bothering with a reset pin// ---------------------------------------------------------------------------// Main setup function// ---------------------------------------------------------------------------void setup(){pinMode(PwrPin, OUTPUT);digitalWrite(PwrPin, HIGH);if (DEREPin > 0) pinMode(DEREPin, OUTPUT);Serial.begin(57600); // Main serial port for debugging via USB Serial MonitormodbusSerial.begin(9600); // The modbus serial stream - Baud rate MUST be 9600.delay(2000);// Start up the sensorsensor.begin(model, modbusAddress, &modbusSerial, DEREPin);// Start the OLEDdisplay.begin(SSD1306_SWITCHCAPVCC, 0x3C, false);display.clearDisplay();display.setTextSize(1);display.setTextColor(WHITE);display.setCursor(0,0);// Turn on debuggingsensor.setDebugStream(&Serial);// Start up notedisplay.println("Yosemitech ");display.println(sensor.getModel());display.display();display.println(sensor.getParameter());display.println("Sensor");display.display();delay(3000);// Get the sensor's hardware and software versiondisplay.clearDisplay();display.setCursor(0,0);float hardwareV, softwareV;sensor.getVersion(hardwareV, softwareV);display.println("Hardware Version:");display.println(hardwareV);display.println("Software Version:");display.println(softwareV);// Get the sensor serial numberString SN = sensor.getSerialNumber();display.println("Serial Number:");display.print(SN);display.display();delay(3000);// Get the sensor calibration status (pH only)if (model == Y532){display.clearDisplay();display.setCursor(0,0);byte status = sensor.pHCalibrationStatus();display.println("Calibration Status:");display.print("0x0");display.println(status, HEX);display.display();delay(3000);}// Get the sensor's current calibration valuesif (model != Y532){display.clearDisplay();display.setCursor(0,0);float Kval = 0;float Bval = 0;sensor.getCalibration(Kval, Bval);display.println("Current Calibration Equation:");display.print(Kval);display.print("*raw + ");display.println(Bval);display.display();delay(3000);}if (model == Y511 || model == Y513 || model == Y514){display.clearDisplay();display.setCursor(0,0);// Check the wiper timinguint16_t interval = sensor.getBrushInterval();display.println("Sensor auto-cleaning interval: ");display.print(interval);display.println(" minutes");display.display();delay(3000);}// Tell the sensor to start taking measurementsdisplay.clearDisplay();display.setCursor(0,0);display.println("Starting sensor measurements");display.println();success = sensor.startMeasurement();if (success) display.println(" Measurements started.");else display.println(" Failed to start measuring!");display.display();// The modbus manuals recommend the following warm-up times between starting// measurements and requesting values :// 2 s for whipered chlorophyll// 20 s for turbidity// 10 s for conductivity// On wipered (self-cleaning) models, the brush immediately activates after// getting power and takes approximately 10-11 seconds to finish. No// readings should be taken during this time.// pH returns values after ~4.5 seconds// Conductivity returns values after about 2.4 seconds, but is not stable// until ~10 seconds.// DO does not return values until ~8 seconds// Turbidity takes ~22 seconds to get stable values.display.clearDisplay();display.setCursor(0,0);display.println("Allowing sensor to stabilize..");display.display();for (int i = 10; i > 0; i--){display.print(i);display.display();delay (250);display.print(".");display.display();delay (250);display.print(".");display.display();delay (250);display.print(".");display.display();delay (250);}display.display();if (model == Y511 || model == Y513 || model == Y514){display.clearDisplay();display.setCursor(0,0);// We'll run the brush once in the middle of thisdisplay.println("Activating brush.");display.display();success = sensor.activateBrush();if (success) display.println(" Brush activated.");else display.println(" Failed to activate brush!");display.display();}if (model == Y511 || model == Y513 || model == Y514 || model == Y510){display.clearDisplay();display.setCursor(0,0);display.println("Continuing to stabilize..");display.display();for (int i = 12; i > 0; i--){display.print(i);display.display();delay (250);display.print(".");display.display();delay (250);display.print(".");display.display();delay (250);display.print(".");display.display();delay (250);}display.println("\n");display.display();}}// ---------------------------------------------------------------------------// Main loop function// ---------------------------------------------------------------------------void loop(){display.clearDisplay();display.setCursor(0,0);display.setTextSize(2);// send the command to get the valuesfloat parmValue, tempValue, thirdValue = -9999;sensor.getValues(parmValue, tempValue, thirdValue);display.println("Temp (C):");display.print(" ");display.println(tempValue);display.print(sensor.getParameter());display.print("(");display.print(sensor.getUnits());display.print("): ");display.print(" ");display.println(parmValue);if (model == Y532 || model == Y504){display.println("thirdValue:");display.print(" ");display.println(thirdValue);}display.display();// Delay between readings// Modbus manuals recommend the following re-measure times:// 2 s for chlorophyll// 2 s for turbidity// 3 s for conductivity// 1 s for DO// The turbidity and DO sensors appear return new readings about every 1.6 seconds.// The pH sensor returns new readings about every 1.8 seconds.// The conductivity sensor only returns new readings about every 2.7 seconds.// The teperature sensors can take readings much more quickly. The same results// can be read many times from the registers between the new sensor readings.delay(1700);}
Are you using breadboards or have you made a custom circuit of some kind? Post a picture.
Yes i put it in.
- By what is the Yosemitch sensor powered and at what voltage?
Connected in a levelshifter from a arduino mini pro.
- Exactly what RS485 to TTL adapter do you have connected between the A and B (green and white) of your Y500B and your NodeMCU (brand, chipset, etc)
- What powers the RS485 adapter and at what voltage?
- Does the adapter require the use of a pin to change the direction of communication or does it have automatic flow control?
https://www.aliexpress.com/item/32647766464.html I dont think it got flowcontrol. Its powered by the vcc(3.3v) from the nodemcu.
- <li style=”list-style-type: none;”>
<li style=”list-style-type: none;”>
- Are there any LED’s on your adapter?
- If so, do you see the power, Tx, and Rx LED’s light up appropriately?
Yes it glows bright red.
- What level shifters are you using (brand, etc)?
- Are your level shifters between the Tx and Rx of your adapter and the pins of your NodeMCU?
- If not, where are they in the chain?
- What voltages are you shifting to and from?
- I have not succeeded in using external level shifters on a breadboard with an RS485 adapter so I am quite skeptical of a set-up that requires them.
Its chinese and honestly i dont know as i said before i just continued someones old project and couldnt find the shifter on the internet.
- Are you sure you have Tx and Rx coming out of the adapter connected appropriately the pins you are assigning as Rx and Tx in SoftwareSerial?
- Have you tried reversing the Tx and Rx?
Everything correctly wired because it worked before i used it.