You have posted code without using code tags. The code tags make the code look
like this
when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.
aarg:
You have posted code without using code tags. The code tags make the code look
like this
when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.
change all instances of 'Serial1' to 'levelSensor'. Tidy up all the serial references and verify the baud rate of the level Sensor (is it really 4800)?
aarg:
change all instances of 'Serial1' to 'levelSensor'. Tidy up all the serial references and verify the baud rate of the level Sensor (is it really 4800)?
4800 codeline is commented
but now I'm getting error Arduino: 1.8.10 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"
C:\Users\User\AppData\Local\Temp\arduino_build_199960\sketch: Access is denied.
Error compiling for board Arduino Nano.
#include <Wire.h>
#include <EEPROM.h>
#include <VL6180X.h>
#include <SoftwareSerial.h>
//SoftwareSerial levelSensor(10, 11); // RX, TX
#define LED 13
VL6180X sensor;
float dist, sens;
int count;
uint32_t currentMillis;
uint32_t previousMillis;
float duration;
void setup()
{
Wire.begin();
sensor.init();
sensor.configureDefault();
sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 90);
sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 150);
sensor.setTimeout(500);
sensor.stopContinuous();
delay(500);
sensor.writeReg(0x10A, 0x08);
sensor.startRangeContinuous(100);
Serial.begin(9600);
levelSensor.begin(9600);
Serial.flush();
levelSensor.flush();
// levelSensor.begin(4800);
//ideas
// Look at docs to see how to improve accuracy
// only use samples that converged
// look into whether samples are used twice or other issues with the uncoltrolled loop
// allow more variability in the output of the sensor and average in the mcu
// measure drift by connecting to the CNC machine to get precise moves
count = 500;
}
void(* resetFunc) (void) = 0;
void loop()
{
sens = sensor.readRangeContinuous();
if (sens < 255)
{
if ( abs(sens - dist) > 10.0) {
dist = sens;
}
dist = .995 * dist + .005 * sens;
}
count = count --;
if (count == 0)
{
count = 1;
// Serial.print("\t Range: ");
// Serial.println(dist);
}
{
if (dist >= 40.00 && dist <= 120.00)
{ currentMillis = millis();
}
if (dist >= 120.00 ) {
Serial.println("\t Measurement Complete");
exit;
}
if (dist < 40.00) {
Serial.println("distance <40");
exit;
}
void duration_data(void);
{
duration = (currentMillis / 1000.0);
Serial.print("distance");
Serial.print("\t\t");
Serial.println(dist);
Serial.print("Duration secs ");
Serial.print("\t");
Serial.flush();
Serial.println(duration);
if (Serial.available()) { // If anything comes in Serial (USB),
levelSensor.write(Serial.read()); // read it and send it out levelSensor (pins 0 & 1)
}
duration = 0;
// levelSensor.print(duration);
delay(300);
}
}
}
rockwellramesha:
I, couldn't find a suitable document, please advise a link
If you look at the sticky threads at the top of this forum, you will find a great collection of such links. Every Arduino function and language feature is also documented on this website under the "resources" tab.
aarg:
If you look at the sticky threads at the top of this forum, you will find a great collection of such links. Every Arduino function and language feature is also documented on this website under the "resources" tab.
aarg - appreciate your support, you have been so patient and kind.