Basic A3144 TACHO for machine tool?

i dont see why it wouldnt be safe :confused: its a power block not direct to the mains lol, used a sacrificial USB cable, stripped the wires ~ 200mm from the socket and identified the + & - and used them to supply power. where am i going wrong lol? regardless its still performing the same either way, i have not added a 4.7K resistor across + and DATA pins of the 3144, enabled pin 2 as PULLUP...

void setup () 
  {
  pinMode(2, INPUT_PULLUP);
  Serial.begin(115200);       
  Serial.println("Frequency Counter");

ive also taken off the bread board and soldered joints where possible to avoid dodgy contacts (cheap breadboard lol)

does anyone have any other suggestions?

Is the ground of the sensor connected to the ground of the Arduino?

If you have the encoder reading and rpm calculation without the display, do you get good results with serial output?

well i took a few steps back with guidance from the following link....

working one step at a time, as a basic magnetic switch to light external LED using arduino as power supply - check, works fine.
then the same situation but to light the onboard LED when magnet detected - check.
next step, simple tacho - nothing on the serial monitor or plotter, litrally no reaction :confused:
this is the simple tacho code...

const int hallPin = 2;
const int maxCnt = 100;

void setup() {
  Serial.begin(9600);
  pinMode(hallPin, INPUT);
}

void loop() {
  unsigned long start = micros();
  int old = 1;
  int cnt = 0;
  while (cnt < maxCnt) {
    int val = digitalRead(hallPin);
    if (!val && val != old) cnt++;
    old = val;
  }
  float seconds = (micros() - start) / 1000000.0;
  float rpm = cnt / seconds * 60.0;
  Serial.print("rpm: ");
  Serial.println(rpm);
}

on the plus side, going back and working through it like this is giving me a chance to brake down the code and actually understand (to some degree) whats happening - what i should have done anyway lol.

and the ground of the sensor goes to arduino ground VIA the breadboard, is it worth trying it direct to arduino? in my head if it worked before as a switch, it shouldnt be any different :/?

You can't imagine how often poor powering comes up here...

This can be a mistake! You must disable interrupts on the line before reading those values, and enable interrupt after it. As You have a delay of 500 ms an interrupt can occur at the same time as the code is reading those 4 + 4 byte long variables.

Ok, would...

detachInterrupt(digitalPinToInterrupt, 2);

before, then...

attachInterrupt(digitalPinToInterrupt, 2);

after, be appropriate?

also would this make a difference to the fact that my serial monitor/plotter is inactive? im assuming thats an issue alone and could do with sorting that out, anyone know of any reason it could be deactivated?
i read a post saying uninstalling/reinstalling the IDE helped but ive done that with no joy :confused:

also could the serial issue be more a hardware issue? i only have this one NANO to hand as im staying with family over christmas, ive got a few NANOs and a few UNOs at mine so if its possibly the issue, i may wait till the 31st when i get home lol

I would focus on the code without interrupts. The last posted tutorial is OK, and you should be able to sort out your issues using it. Your issues are not in the code.

Regarding the Serial monitor, is the baud rate set to the same as in the sketch?

Ok, so when you say my issues are not in the code do you mean its likely or possible that theres an issue with my hardware?
and yes both the sketch and serial monitor/plotter are set to 9600

Yes. Your codes work with test signals applied to pin 2.

ah ok great thank you, i will start from scratch with an UNO when i get home, cheers :slight_smile:

Hi, well i started a fresh - brand new UNO, new A3144, new 10K resistor.
when i compile, its fine, then i go to upload, and it comes up with the following ...

Sketch uses 5440 bytes (16%) of program storage space. Maximum is 32256 bytes.
Global variables use 338 bytes (16%) of dynamic memory, leaving 1710 bytes for local variables. Maximum is 2048 bytes.
"C:\Users\joshh\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\joshh\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM5" -b115200 -D "-Uflash:w:C:\Users\joshh\AppData\Local\arduino\sketches\FA815C52EBBB4378C1D4DA8A8A844449/RPM_intr_nick_gammon_1.ino.hex:i"

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\joshh\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 4.4
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "C:\Users\joshh\AppData\Local\arduino\sketches\FA815C52EBBB4378C1D4DA8A8A844449/RPM_intr_nick_gammon_1.ino.hex"
avrdude: writing flash (5440 bytes):

Writing | ################################################## | 100% 0.73s

avrdude: 5440 bytes of flash written

avrdude done.  Thank you.

i do not understand why its overriding the baude rate :confused: i check that its set to 9600, then after upload it says its been overridden, im very far from an expert (quite far from a beginner haha) - i cannot let this defeat me lol but its getting frustrating now.
i have tried uninstalling/reinstalling the IDE and it was no different, please someone help lol
many thanks,
josh.

also just so you know, the code i just pasted is red from...

avrdude: Version 6.3-20190619

onwards ( in the IDE i mean)

You have posted the results of a successful upload of the code to your Uno. One more thing you can do to confirm is to check the pull down box "Verify code after upload" in the IDE with File> Preferences.

The baud rate for the sketch upload is different from the baud rate used in the sketch for communication with the Serial Monitor. I think this is the sketch you loaded with the posted output.

The posted code wants the monitor to be set at 115200.

 Serial.begin(115200); 

What issues are you seeing?

well when i plug the UNO in, it has been displaying what should be 'niq_ro' but with segments missing (if i restart the UNO, it doesnt seem to replicate the same each time, there will be less or more segments each time :confused: ) then the the display will sometimes display a few random numbers then go blank until restarted.
the display is the last thing that i havent replaced to see if its the issue, could it be that :confused: ? i cant imagine thats it but everything else has been swapped and the issue is still the same, starting to drive me a bit mad now lol.

well i can confirm the display wasnt the problem, i just tried it with a new display and still the same result.

Let me understand. You are now having no issues with the reading of the hall sensor and the Serial output shows the correct rpm.

Your present issues are will the display of the rpm readings, and indeed the display of the set up message "niq-ro".

Have you run the library examples for "LedControl.h". That's the place to start with debugging the display.

.

Hi, yes basically the hall sensor is being read and the serial monitor shows largly the correct rpm, the only thing is every few readings it shows a massively high RPM, heres the serial output...

RPM: 611.76
RPM: 616.39
RPM: 616.90
RPM: 613.06
RPM: 613.24
RPM: 609.93
RPM: 617.99
RPM: 619.51
RPM: 615.76
RPM: 617.89
RPM: 619.99
RPM: 621.39
RPM: 626.92

other than that yes the only issue is displaying it - but like i said ive tried 2 brand new 7seg/8digit displays (MAX7219) with the same results so assuming the problem must be with the code :confused: ?

I just ran the LedControl example - intead of showing 'arduino' one letter at a time on digit 0, it will do the first couple of letters then the next on the next digit, or repeat letters - and the numbers afterward were almost entirely random :confused:

sorry i had only pasted the correct rpms haha

RPM: 220.79

RPM: 6671.95

RPM: 238.71

RPM: 235.67

RPM: 232.92

RPM: 237.45

RPM: 226.34

RPM: 6677.89

RPM: 243.31

RPM: 7016.72

RPM: 249

Good news! i just wired a 5V 1A power supply to the MAX7219 board, with the GND also going to the arduino and it worked :slight_smile: it does still jump up to ridiculus numbers from time to time but still a massive improvement :slight_smile: thanks ever so much for your help so far, any ideas about why it would jump like that?