Linear Encoder (suspension diagnostics)

I had a look at the encoder company you linked in your first post. They seem very suitable, especially rugged enough for your task. I would consider their ID1102L model together with a TPLS01 scale. If you open the datasheet you find selection tables on page 4.

  1. Max speed: You wrote that you need 10m/s. To have some headroom I'd go for the 30m/s version which -> BB = 23 in table 2. This tells you that CC (table 3) needs to be smaller than 07.
  2. Resolution: Table 3 tells you that they have a version with a resolution of 0.15mm (CC = 03). At your max speed of 10m/s this version would produce a count rate of (10m / 0.15mm)/s = 66.7 kHz.
  3. Which processor: 66.7kHz should be no problem, even for one of the ancient AVR boards. Anyway, I suggest to use something faster so that you don't have to waste time with optimizing code. A Teensy 3.2 (90MHz, ARM) would be more than sufficient for such a task. The T3.2 is 5V tolerant which might simplify the connection of a 5V encoder. If you plan to have some buffer between the processor and the encoder anyway, you might go for a 600MHz T4 (not 5V tolerant) which costs about the same as a T3.2 (~20EUR)

Here a video showing a T3.2 reading an encoder (40000cts/rev, attached to the motor axis) at 800kHz, running a webserver and transmitting the measured counts via a websocket connection to a client (tablet)

Was thinking. Can you get a hall sensor to work in both ways? I know they use them on ABS sensors on cars but would you be able to have a sensor which can pick up the change in motion?
Was just thinking i could get a laser cut strip?

Mount a series of hall switches where only one at a time can be actuated by a target on the piston. Code could be developed to (roughly) sense position, direction, and velocity (time between actuations).

YMMV

Good evening all.

I have bought myself the nano 33 IOT and a GP2Y0A41SK0F Sharp, Reflective Sensor

I have had a play with the nano and set it all up. Managed to get the accelerometer working which i think would really help on this project.

On further reading up would i need to purchase a SD card reader to record the data that i want to record or can i get the data stored on the namo and retrieve it after the experiment?

So sorry if this is a simple questiion. i know what i want in my head but getting it into a arduino is another thing

Good evening lawton74 !

the project is progressing !
to start using the encoder (it may be necessary to adapt the electrical levels of conductors A and B of the encoder to pins 2 and 3 of the nano, and perhaps insert two protection transistors, for the encoder outputs)

  // Arduino pro-mini 5V 16 M         *optical* encoder          A & B on pin 2 & 3 
  // if you want to use a mechanical encoder, signals A & B *MUST* be (electricaly) properly debounced !

  #define SignalA          B00000100                          // encoder signal pin 2 (port D)
  #define SignalB          B00001000                          // encoder signal pin 3 (port D)
  #define SignalAB         B00001100                          // both signals
  volatile int             encodPos;                          // encoder position
  volatile byte            LastPortD = SignalA;               // previous A/B state 
  int encodLastPos;                                           // ----- for this demo, previous position


void setup(void) {
  PORTD |= SignalAB;                                          // internal pullups on interrupt pins 2, 3
  Serial.begin(115200);                                       // fast fast fast !
  attachInterrupt(digitalPinToInterrupt(2), ExtInt, CHANGE);  // encoder pin 2 interrupt vector
  attachInterrupt(digitalPinToInterrupt(3), ExtInt, CHANGE);  // encoder pin 3 interrupt vector 
}


void ExtInt() {                                               // OPTICAL ENCODER ext. interrupt pin 2, 3
  byte PortD =      PIND  & SignalAB;                         // 
  if ((PortD ^ LastPortD) & SignalA)   encodPos++;            // Rotation ->    {encodPos++; Sense = 1;}
  if ((PortD ^ LastPortD) & SignalB)   encodPos--;            // Rotation <-    {encodPos--; Sense = 0;}
  if ((PortD) &&  (PortD != SignalAB)) PortD ^= SignalAB;     //                              (swap A-B)
   LastPortD  =    PortD;                                     //                  mieux vaut faire court
}


void loop(void) {                                             // MAIN LOOP
  if (encodLastPos != encodPos) {                             // when the encoder change,
    encodLastPos = encodPos;                                  //
    Serial.println(encodPos);                                 // print encoder position
  }                                                           //
}                                                             //


I read a bit fast! It's a distance sensor, not an encoder that you bought. My little example program above was to test an encoder. You want to measure the variation of the fork position with this distance sensor, maybe?

Morning Pat thanks for you help.

I decided to just get the ball rolling and use this sensor as i think it will be easier for me to understand.

If i explain what i would like to have would you please tell me what you think would be possible and not.

So i would like to put a switch on the handle bars and at the start of the race press the button and the arduino would start up. While riding around the accelerometer and the sharp sensor would work together to work out what is happening.
To save on the amount of data stored i would like the arduino only to record when the accelerometer reaches a value, and then record the values 5 seconds before and after.
Eventually i would like to be able to use the sensor, accelerometer, gps and real time so we can make it easier to see the results.

I have purchased a rechargeable 4.8v 70ma x 16h but just reading the 33 IOT can only run on 3.3 volts, but on the box it says power supply input-vin says 4.5-21 volts.

Is there anyone (company) that writes codes or do you think this is something that i would be able to learn over time?? (i do want to learn but if you think this is 3 years down the line learning i understand)

Hello Lawton74

you can quickly learn how to use the functions of your arduino, it is made for that ! especially by using already existing and tested functions, that the participants will be happy to give you :wink: luni 64 masters the subject very well, especially for the stepper motors. Start small (you have never programmed an arduino ? start by making the internal led blink, to understand how to do it).

Then, in 1 or 2 hours, you can test your Sharp sensor on a work table, and see how it reacts when you move it by hand, and by displaying the values on the screen. Once you are comfortable with the reading of the Sharp sensor, you will go to the next step, with the help of the forum participants... anyway, it's long even for those who do this all day, ahahaha

The 33 iot works in 3.3V (internal), but your 4.8V battery can power it, a voltage regulator brings back this 4.8V in 3.3V on the board. Always be careful to respect the polarity when connecting! but to start, you will not need this battery, the nano connected to the PC will naturally be powered by the USB plug.

No never had an arduino before, so this is all new to me. In have managed to use the example down load to get the LED to flash and changed the flasher speed.

There is a few people on youtube that have got the Sharp sensor to work with the arduino and say there is a down load. I would prefer to learn the codes so I can change or fix a problem if one occurs.

void setup() {
// put your setup code here, to run once:
pinMode(A5,OUTPUT);
pinMode(A3,INPUT);
}

void loop() {
// put your main code here, to run repeatedly:
analogWrite(A5,HIGH);
analogRead (A3);
Serial.print (A3);
}

Evening Pat. This will look pathetic to you but i can see the input.

I have the sensor VCC to pin A5 and the gnd to the grn and the signal wire to A3.

Because im on the 33 IOT i can't connect the VVC to a 5 volt out put like the UNO's. Iv googles voltage out put to see the code but all i can see it High

Hi, good start for the code! Here is the technical documentation of the sensor

which indicates that it must be powered in 5V, so we must abandon the Vcc of the sensor on pin A5 (it was a good idea to make the whole compatible in 3V, but the pins of the nano 33 iot provide only the third of the current requested by the sensor, 7mA supplied by the pin, for 22 mA requested by the sensor).

You have to put this Vcc of the sensor on the VUSB pin (pin 27) AND POWER THE NANO THROUGH USB; be careful, you have to establish an electrical bridge (delicate soldering!)

it seems that the output voltage of the sensor does not exceed 3.3V, but it is to be checked. If it is necessary, we will lower a little this output voltage with 2 resistors.

and add in the setup block : Serial.begin(115200);

and maybe : Serial.println (analogRead(A3));

I will order this sensor, to play with it !

Thanks Pat.
So with the operating Voltage on the sensor 4.5 - 5 volts can i still use the (NiCd battery pack 4.8V 700mAh HB) to power up the Arduino and the sensor?

Also if you are purchasing the sensor i will send you some money over.
Really appreciate this.

With the NiCd pack, you will have about 6.0 V when well charged, a voltage that will drop to 4.5 V after a few hours of use, if the total consumption of the project is about 50...80 mA (22 mA for the sensor, and the rest for the nano). This is enough to power the nano; the sensor requires between 4.5 V and 5.5 V, and it is this 5.5 V limit that is troublesome for a battery charged to 6.0 V. We could put a Schottky diode at the input of the sensor to 'lose' 0.3 V; it's ideal when the battery is charged to 6.0 V, but we can only use it until 5.0 V of discharge (the voltage range of the sensor and the battery are narrow and not quite adapted, but it's possible to start the project). Thanks for your proposal, but I'll buy it myself, it will surely be useful later!

Pat if you think it would be easier to purchase a different battery i don't mind. I have an account with RS components so if you think there is a better one on there please let me know.

You have an RS account? so do I! the 4-cell NiCd battery is very good to start this project; if I went into technical details, it was not to point out the arguments against this choice of battery. Anyway, the choice of a battery is always, always a search for the best compromise, and this gives rise to tests and discussions for each new project: between 1.5V (alcalin) or 1.2V (Ni-xx), or 3. 7V (Li-xx) cells, we have to find the best combination to get as close as possible to the operating voltage of the modules to be powered, directly or through a regulator, with packs of 2, 4 or 5 cells to power different modules operating at 3 or 5V, with different acceptable voltage ranges... it's the same search every time! the 4-cell NiCd battery is a good choice for the couple nano-sharp sensor.

Sorry Pat was just saying i have a RS account so if there was a battery that you think would work better please look on there. Was trying to save another email coming every day off another electronics company. When trying to find a sensor i must have added me email address 20 times now all i get is emails on new products etc.

Brilliant will stick with this one for now then.

Add in a buck converter set to 4.5v, you don't need many amps so it will be small and cheap. I'd stick to Nicad, lipo batteries need much more care and are prone to catch fire if punctured.

I get my Sharp sensor tomorrow, get it working and we'll talk!

1 Like

It's done! It works well!
I started from
https://robojax.com/learn/arduino/?vid=robojax-sharp_IR

and I chose the library (choice 8 in the list) to get this (unzip, then put the result-folder in your library,

SharpIR-master.zip (5.3 KB)

then create a folder named "SharpSensorCm01" in your workspace, and copy the program (with the same name) that I slightly modified (from the example in the zip file):

SharpSensorCm01.ino (1.3 KB)

#include <SharpIR.h>

#define ir A3                                            // ir: the pin where your sensor is attached
#define model 430                                        // model: determines your sensor:  GP2YA41SK0F --> "430"
SharpIR SharpIR(ir, model);                              // (430 : see 'readme.txt' in library)


void setup() {                                           //
  Serial.begin(115200);                                  //
}


void loop() {                                            //
  delay(800);                                            //
                                                         //
  unsigned long pepe1 = millis();                        // takes the time before the loop on the library begins
  int dis = SharpIR.distance();                          // this returns the distance to the object you're measuring
  unsigned long pepe2=millis()-pepe1;                    // the following gives you the time taken to get the measurement
                                                         //
  Serial.print("Mean distance (cm): ");                  // returns it to the serial monitor
  Serial.print(dis);                                     //
  Serial.print("     Time taken (ms): ");                //
  Serial.println(pepe2);                                 //
}

Be careful to respect the polarity when connecting the sensor
(I didn't have a connector, I soldered)

use a white sheet of paper as a reflection plane

the values of distances in cm seem a little strong ? (I would not have indicated in the program the good type of sensor?)
but they vary very well between 4 and 30 cm

Pat have you run the 1K resister in-between the sensor and the arduino?

Or did it work just up loading this program and running the pins we talked about.
Also the bridge on the back to make the 5 Volt?