Jump to content

Gina

Beyond the Event Horizon
  • Posts

    45,326
  • Joined

  • Last visited

  • Days Won

    120

Everything posted by Gina

  1. I'm just wondering how often I want to read the data. Also, there are two ways of reading the wind speed - count the pulses or measure the time between pulses. Maybe use both depending on the wind speed. Interval for low speeds and count for higher speeds. If I were just to use the count and sample once per second the speed would be directly in mph. Maybe I don't need anything better and that would definitely be the easiest. I think I would really like a faster update on the analogue wall indicators though. Updating once a second would look very jittery - I guess I could smooth it.
  2. PHEW!! Sometimes I'm too blooming clever for my own good Trouble is I like to understand what I'm doing! Now to put everything back together... Then to try it from the RPi. I also have the wind speed counter routine to add to the sketch.
  3. Rewired the Arduino Nano to use D3-D5 and IT WORKS Guess I should have just followed the instructions and not tried to second guess it
  4. OK - I've got it The MLX90316.cpp code is independent of the standard Arduino SPI system and by way of the main sketch reassigns these functions to D3-D5 and also switches between MOSI & MISO by switching the pin between output and input respectively. I'll change my Arduino Nano connections and try again.
  5. Thanks I have the baud rates on both set to 115200 as per the sketch. I'm using different pins on the Arduino Nano though. I was going by the Nano connection diagram which shows SPI as D10-D13 rather than D3-D5. I'll try D3-D5 then. From your pic you are indeed connecting to D3-D5 on the Mega. I must be missing something - I'll examine the MLX90316.cpp code again.
  6. Relax??? What's that? Ah yes - playing my vinyl
  7. So what shall I do for the rest of the evening?
  8. Simpler than a Gray encoder is it ???????????????? Hmm... Might be if it worked!
  9. Used a transistor instead of a FET with a resistor in the base line. Still not working Guess I'll connect my little digital oscilloscope to it tomorrow and see if I can tell what's happening.
  10. Ordered some - due Tuesday or Wednesday.
  11. Connected to MISO instead of MOSI on the Arduino and added a 1k2 resistor to +3.3v. Still not working and I can't find a FET though I'm sure I have a few.
  12. Data is read in to the Arduino (master) from the MLX90316 (slave) therefore the data channel is MISO. The MOSI line sends data to the slave to make it do something, in this case read the angle. The way I have it connected it couldn't possibly work! It might work without MOSI as the SS (Slave Select) may trigger the output though that isn't the way it's described in the datasheet. But at least one person seems to have it working without MOSI.
  13. I think I have MOSI & MISO mixed up! I'll re-read the datasheet.
  14. That still produced -1 so the data is neither a valid angle nor a valid error code. Changing the code to return -rr if not a valid angle produced a code of 1 meaning rr was -1 ie. all 1s - a data transfer error. The Arduino is not reading the MLX90316 output register or the register is stuck on all ones. Next stage then is to add the FET and resistor to see if that cures it but if not I shall have to assume the chip is damaged. I did buy a spare.
  15. Yes and that's probably the easiest thing to do. I only have to take this code section and produce a general negative number from the error code. I can interpret it later. if ((rr & 3) == 2) { if ( rr & (1 << 4)) ret=-2; // signal to strong if ( rr & (1 << 5)) ret=-3; // signal to weak } I propose this code :- if ((rr & 3) == 2) { ret=-rr; // error code as negative number }
  16. I could edit the code in MLX90316.cpp to take the errors and convert to a negative number to show what's wrong. I don't think it's anything to do with the MISO and FET etc. though it wouldn't take much to add the components birds-nest fashion I guess that would eliminate that possibility.
  17. The MLX90316.cpp reads the data from the device and parses the data to determine if the angle is valid or if there's an error in conjunction with information from the datasheet. If the LSB 2 bits are 0 1 the data represents a valid angle otherwise there is an error condition as shown by the table in the second screenshot.
  18. YEP!! Returns angle if angle data is valid else -1. If the magnetic field is too strong or too weak it returns -2 or -3 from these lines of code :- if ( rr & (1 << 4)) ret=-2; // signal to strong if ( rr & (1 << 5)) ret=-3; // signal to weak SO a return of -1 indicates invalid angle data (from whatever cause other than magnetic field strength).
  19. I think the answer to the -1 display might be in here :- /* MLX90316.cpp - Library to use with Melexis MLX90316 rotary encoder chip. Created by Martin Nawrath KHM 2010. http://interface.khm.de Released into the public domain. */ #include "Arduino.h" #include "MLX90316.h" // constructor MLX90316::MLX90316(){ }; // attach void MLX90316::attach(int pinSS, int pinSCK, int pinMOSI ) { _pinSS = pinSS; _pinSCK = pinSCK; _pinMOSI = pinMOSI; pinMode(_pinSS , OUTPUT); pinMode(_pinSCK , OUTPUT); pinMode(_pinMOSI , OUTPUT); } //****************************************************** int MLX90316::readAngle() { byte bb; int ret=-1; unsigned int rr; long int lo; digitalWrite(_pinSS,0); bb=_spiByte(0x55); // send sync byte ( AA reversed order = 55?) bb=_spiByte(0xFF); // send sync byte FF) bb=_spiByte(0xFF); // receive 1. byte of mlx msb data rr= (bb << 8); bb=_spiByte(0xFF); // receive 2. byte of lsb mlx data rr=rr+bb; if ((rr & 3) == 2) { if ( rr & (1 << 4)) ret=-2; // signal to strong if ( rr & (1 << 5)) ret=-3; // signal to weak } if ((rr & 3) == 1) { // valid angle data ? rr = (rr >> 2); lo= rr ; lo=lo * 3600 / 16384; // scale output to 360 deg, untit in tens of deg. ret= lo; } digitalWrite(_pinSS,1); return(ret); } //************************************************************* // send and receive SPI byte to/from MLX90316 Chip uint8_t MLX90316::_spiByte(uint8_t tx) { byte rxb=0; for (int ix = 0; ix < 8; ix++){ // receive/transmit 8 SPI bits digitalWrite(_pinSCK,1); // clocksignal positive slope rxb = ( rxb << 1); // shift received byte left pinMode(_pinMOSI,INPUT); // switch MOSI pin to input digitalWrite(_pinMOSI,1); // turn port internal pullup resistor on if (digitalRead(_pinMOSI) ==1) rxb = rxb | 1; // read respose bit from sensor digitalWrite(_pinMOSI,0); // turn port internal pullup resistor off pinMode(_pinMOSI,OUTPUT); // switch MOSI pin to output // write SPI transmit bit to sensor if ((tx & 1) != 0) digitalWrite(_pinMOSI,1); else digitalWrite(_pinMOSI,0); tx= ( tx >> 1); digitalWrite(_pinSCK,0); // clocksignal negative slope digitalWrite(_pinMOSI,0); // set MOSI databit 0 } return(rxb); }
  20. Um... I think you've got it the wrong way up
  21. Thought the damping magnets could be causing the problem so removed them - now about 4m from the sensor chip. Tried the axle magnet on top of the chip again but still no joy. Wonder if it does need the FET and resistor from MISO. I would have thought that if this was the problem the check would fail.
  22. The MLX90316 check is fine otherwise it wouldn't read the angle and display an angle of -1. So I guess this means the chip is working. void loop() { if (mlxMetro.check() == 1) { ii = mlx_1.readAngle(); Serial.print(ii); Serial.println(""); } } I've tried removing the sensor from the mounting and also pulling out the vane axle with its magnet. Also tried the axle magnet on the top of the sensor chip but still a repeating "-1" on the display.
  23. Read carefully through the MLX90316 datasheet and can see no mention of error output. But generally where the device gives a positive number to show a measurement an output of -1 indicates an error and therefore I assume that I am getting an error from the sensor chip. I have Googled till I'm blue in the face for any information about MXL90316 errors. The datasheet says an error will occur if the magnetic field is to weak or too strong. So this is one possibility.
  24. Well, that one thing cured but now I'm getting -1 which I reckon is saying there's an error.
  25. I can see why I think Wrong baud rate
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.