0

I'm really new to the Arduino system, and I'm trying to do a project, which is basically a water quality controller, with multiple sensors (pH, Temperature, Conductivity, Dissolved oxygen etc...) which gives us the values for all these parameters.

The code for this project is already written and adapted to the hardware. This code is composed of multiple files (.h and .ccp), 2 files for each sensors and one main file (.ino) to run the complete system. Here is one example file:

/**********************************************************************************
* GravityEc.h
* Copyright (C)    2017   DFRobot,
* GitHub Link :https://github.com/DFRobot/watermonitor
* This Library 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.
* Description:Monitoring water quality parameters Conductivity
* Product Links:http://www.dfrobot.com.cn/goods-882.html
* Sensor driver pin:A1 (ecSensorPin(A1))
* author  :  Jason(jason.ling@dfrobot.com)
* version :  V1.0
* date    :  2017-04-17
**********************************************************************/

#pragma once
#include "GravityTemperature.h"
#include "ISensor.h"

// external GravityTemperature ecTemperature;

class GravityEc:public ISensor
{
public:
    // Conductivity sensor pin
    int ecSensorPin;

    // Conductivity values
    double ECcurrent;


public:
    GravityEc(ISensor*);
    ~GravityEc();

    // initialization
    void  setup ();

    // update the sensor data
    void  update ();

    // Get the sensor data
    double getValue();

private:
    // point to the temperature sensor pointer
    ISensor* ecTemperature = NULL;


    static const int numReadings = 5;
    unsigned int readings[numReadings] = { 0 };      // the readings from the analog input
    int index;
    double sum;
    unsigned long AnalogValueTotal;      // the running total
    unsigned int AnalogAverage;
    unsigned int averageVoltage;
    unsigned long AnalogSampleTime;
    unsigned long printTime;
    unsigned  long tempSampleTime;
    unsigned long AnalogSampleInterval;
    unsigned long printInterval ;

    // Calculate the average
  void calculateAnalogAverage();

    // Calculate the conductivity
    void calculateEc();
};

I work on Arduino IDE 2.0.4, Windows 10, and Arduino Uno.

When I try to Verify the code in Arduino IDE, I always get errors like these:

C:\Users\camil\Desktop\KnowFlow_AWM-master\ArduinoUnoDo\WaterMonitor\GravityEc.h:1:1: error: stray '\357' in program
 /**********************************************************************************
 ^
C:\Users\camil\Desktop\KnowFlow_AWM-master\ArduinoUnoDo\WaterMonitor\GravityEc.h:1:2: error: stray '\273' in program
 /**********************************************************************************
  ^
C:\Users\camil\Desktop\KnowFlow_AWM-master\ArduinoUnoDo\WaterMonitor\GravityEc.h:1:3: error: stray '\277' in program
 /**********************************************************************************
   ^

So, I went to some forums and searched for these stray 357, 273 and 277 errors. I found that these errors were the consequence of the presence of goofy/invisible characters in the code. So I deleted the lines were the error was found (1st line in every code file), and replaced it by:

/****

Result was the same, I got the same errors.

I also found that you can use the function : Tools > Fix Encoding and Reload, but this function seems to not exist in my version of Arduino IDE (2.0.4). Is it normal? This function is used to find the goofy hidden characters, and could be very nice to fix my problem.

I tried uploading the file again from GitHub. Could this be linked to my version of Arduino IDE? I will try to use a former one.

This seems to be a common issue but I really don't understand how to get rid of it!

  • Unfortunately, the error messages are probably not telling you the exact line on which the stray character(s) were found, so fixing just that line is probably not solving the problem. These characters probably ended up in the code files when you copy-pasted code from a website into your editor. I don't use the Arduino IDE, so I can't say why that feature does not exist in your copy/version. However, you should be able to use a standard text editor to see and remove these characters. Or, you can use batch text-processing tools like `sed`. – Cody Gray - on strike Mar 09 '23 at 23:18
  • Actually, in this particular case, you have `:` (full-width colon) characters in your code, I found this by running the code you included here through [an ASCII validator](https://onlineasciitools.com/validate-ascii), which told me exactly which characters were non-ASCII. I suspect you have some kind of text-processing utility that is automatically inserting these characters when you type. As I understand, these full-width punctuation characters are common when writing in East Asian languages, because they match the width of the other ideographs. Turn off those tools when writing code. – Cody Gray - on strike Mar 09 '23 at 23:22
  • Thanks for your answer. I ran all the code files in the ASCII validator, and it did found those full-width colon. So I replaced them all, until all my code files were validated by the ASCII. I then copy-pasted those corrected code into the Arduino IDE interface. But I still get the same error messages. I also tried and older version of Arduino IDE (the 1.8, that was used when the code was written), did not change anything. So now I'll try to rewrite all the code in the NotePad++ myself, and see if it changes something. – Camille Mar 10 '23 at 09:45
  • The most common ones can be searched for directly (and optionally replaced, even ZERO WIDTH SPACE) using a reasonably modern text editor (in regular expression mode): `\x{00A0}|\x{200B}|\x{200C}|\x{2013}|\x{2014}|\x{201C}|\x{201D}|\x{2212}|\x{00E4}|\x{FFFC}|\x{FFFD}|\x{2217}|\x{200C}|\x{202B}|\x{202A}`. – Peter Mortensen Apr 18 '23 at 16:52
  • The order is likely \357 \273 \277 (not \357 \277 \273). That corresponds to 239 187 191 (decimal) → 0xEF 0xBB 0xBF (hexadecimal) → UTF-8 sequence for Unicode code point U+FEFF ([ZERO WIDTH NO-BREAK SPACE](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=65272&number=128)). – Peter Mortensen Apr 18 '23 at 17:28
  • In a modern text editor (I *don't* think the Arduino IDE can do it), it can be searched for (and replaced/deleted) by the [regular expression](https://en.wikipedia.org/wiki/Regular_expression) `\x{FEFF}`. For instance, it works in [Geany](https://pmortensen.eu/world2/2020/03/29/using-geany/) and [Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code). – Peter Mortensen Apr 18 '23 at 17:33
  • But that is not a serious problem. The code can be copy-pasted between such a helper text editor and the Arduino IDE. – Peter Mortensen Apr 18 '23 at 17:38
  • To be more specific, the source code as posted here contains two instances of Unicode [code point](https://en.wikipedia.org/wiki/Code_point) [U+FF1A](https://www.charset.org/utf-8/66) ("FULLWIDTH COLON"): UTF-8 sequence 0xEF 0xBC 0x9A (octal \357, \274, \232). This ***doesn't*** correspond to the numbers reported in the main text (\357 \277 \273). It can be searched for regular expression `\x{FF1A}`. The two instances are in the code comments. I don't know if this would result in a compile error or not (I think it does). – Peter Mortensen Apr 25 '23 at 16:11
  • But the OP has probably left the building: *"Last seen more than a month ago"* – Peter Mortensen Apr 25 '23 at 16:14

0 Answers0