Go Down

### Topic: Pulse a 5V VCC pin with 18V to set EEPROM values... say what!? (Read 1 time)previous topic - next topic

#### Koepel

#15
##### May 22, 2018, 05:20 amLast Edit: May 22, 2018, 05:34 am by Koepel
You want to use that special feature that the IRP keeps the register address at 0x20 when reading the angle. I wanted to go slow and keep that for later.

The "uint16_t" is a unsigned int of 16 bits.
The normal 'int' type is 16 bit in a Arduino Uno and 32 bit in a Arduino Due. That is why the "uint16_t" is used, because that is always 16 bits.

I'm confused with "A1335" and "ANG", the names are so short !

Both me and the compiler are confused with this:
Code: [Select]
`angle_deg = raw_data*360/4096;`
The "raw_data" is a unsigned integer, the 360 and 4096 are integers, and after the calculation it is converted to a float. I prefer to do that calculation with floating point calculations.

Don't use a Wire.endTransmission() after a Wire.requestFrom(). That is a number 2

Divide by 16 for binary to decimal ? When a variable has a certain value, that value can be printed as a decimal number or a binary number, but the value of that variable is the same. If you put 180 in a variable, that variable is 180. A number is a number.

I prefer to use local variables when it is used locally. You can declare local variables in the loop(). If you remove the global 'angle_deg' and 'raw_data', then you can try this:
Code: [Select]
`void loop() {  unsigned int raw_data;          // The raw data from the sensor ANG register.  float angle_deg;                     // After math on value store a degree out of 360  Wire.requestFrom(A1335,2);         // request two bytes from sensor    raw_data = Wire.read();                // read first/High byte  raw_data <<= 8;                       // shift data over to make space for Low byte  raw_data |= Wire.read();                // OR function to store low byte    raw_data &= 0x0FFF;          // strip highest 4 bits with bitwise AND operation    angle_deg = (float) raw_data / 4096.0 * 360.0;   // calculation with float  Serial.print("Angle degree > ");          // Print angle in degrees  Serial.println(angle_deg);  Serial.println (" ");  delay(1500);  // wait so human can read it}`

The "(float) raw_data" means that "raw_data" is converted into a float value, and after that the math is done with 4096.0 and 360.0
Do you see the "4096.0" and "360.0" instead of the "4096" and "360" ?
When the compiler sees "4096.0" it uses that as a float number. When the compiler sees "4096" it uses that as integer number.

Please show your new sketch. I prefer to see the new sketch, even if only a comma has changed.

#### Tjaart

#16
##### Jun 14, 2018, 08:19 am
Hi Koepel

After your help I got it working. Vid

The oscilloscope I ordered never arrived from China but did get my money back.
So Have to order that again from some where else.

But I went on with the project and got some cheap steppers, Arduino due and switch mode power supply and so on.

Working towards Due running four steppers with the sensors as position fed back for steering and 4X DC motors.

Parts still arriving. This is what I have so far:

picture to big!  any way... It just showed the Due with parts assembled in newly 3D printed test setups.

Should have more parts and time next week to do better post.

#### Koepel

#17
##### Jun 14, 2018, 08:57 amLast Edit: Jun 14, 2018, 09:05 am by Koepel
Nice. I think you need to take a few samples with analogRead() and use the average. That will make the value a lot more steady.

An oscilloscope ? There are very nice USB oscilloscopes. Then you don't have to pay for a screen. A digital oscilloscope is not the same as an old analog oscillope from a yard sale, you need a high sample rate or you miss a lot.
It did not arrive ? I have changed from Ebay to AliExpress. With Ebay it is very hard to get money back. I think that the sellers on AliExpress get their money after I confirm that it was received, so the sellers try a little harder to do their best.
The saleae USB oscilloscopes are very nice, but also super extremely over-the-top totally nuts expensive. However, in my opinion they set the standard for hardware and software for a good product.
There are cheaper USB oscilloscopes that can be used with a open source interface: PulseView/sigrok.
A poor man's solution is a attenuator of 1:10 with resistors and use the line-in of a computer together with Audacity. That is even dual channel (stereo).

Go Up