New to Arduino coding with complex sensors

Hello everyone,

Right so cutting to the chase, I have a project that is to develop a crankshaft balancer, I've rewired it completely according to the wiring diagram my supervisor gave me and now I'm at the stage where I need to actually start coding to get the thing working and giving me outputs. But I'm brand new to Arduino and I have no clue what I'm doing, taking small steps I'm trying to get a magnetic pickup to give me outputs, even getting help from my friend that did a bit of Arduino programming before I can't understand what I'm doing.

So this setup essentially uses a Mega 2560 as a central control unit, with a magnetic pickup and two Wheatstone bridges wired to it, the magnetic pickup has apart from the 5v and gnd ofc, 4 connectors labelled MISO MOSI CLK and 5(ohms), imagine the ohms symbol was there. The 5ohm is wired to PWM pin 9 on the the board and the other 3 to pins 50, 51, and 52 on the digital side which turned out to be the MISO MOSI and SCK pins. Thing is I don't understand the whole sending inputs to the "slave" board or what the Clock does, or even less what the 5ohm does, I somewhat understand what PWM does but yeah this isn't good.
But now that I have all that info I still don't even know where to begin, I've looked and played about with the codes on the main Arduino pages about using analogue sensors but I still don't understand anything about it.
If you guys could like clarify what is should take as the output and which ones are the inputs that I need to send to the board and essentially how to code for this kind of sensor since I really have no clue about anything.

Thanks in advance.

Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

Topic moved to a more suitabel location on the forum.

Please post here a link to the exact pickup you have bought, and a couple of pictures of the connector and your current wiring.

mag pickup: https://www.mouser.co.uk/ProductDetail/ams-OSRAM/AS5147P-TS_EK_AB?qs=Rt6VE0PE%2FOfngSpzc2DH8w%3D%3D&mgh=1&vip=1&gad_source=1&gclid=CjwKCAiA_OetBhAtEiwAPTeQZ-NcXLEzEHu8U_K-Irj0Y-zn4K2ihd_cJtAioM4yV6taczfyvzvVrRoCjCMQAvD_BwE


the thing is not set up at the moment but that's the wiring diagram for it, bottom right is the magnetic pickup

There's no 5(ohms) connector, where do you see it?

image

It looks like a standard SPI connection, so you can start by connecting it to SPI pins.
Arduino Mega SPI pins are: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). (but also available on the ICSP connector).
For more information on SPI, you can find tons of material on the net, but you could start here:

This is a conceptual drawing of SPI bus:

once correctly connected, the next step is the code, so as soon as you'll get into coding post here your code together with real wirings you used and a decription of what it does (and/or doesn't).

1 Like

Thanks,
The 5ohm I might just be a very scratched away Sn, I'm the second person attempting this project hence the sensors aren't new and why I was following a pre-made wiring diagram.

Ok, so CSn is a SS pin, but it doesn't matter if connected to a regular or a PWM pin, it's just a "client selection", to enable the client the server needs communicating to (see the previous SPI diagram).

If you want to read and start to understand something about SPI, there are hundreds of sources, starting from Wikipedia (recommended):

or many other documents/presentations, like THIS.

Right sorry to bother you again,

#include <SPI.h>

#define ANGLE_REG 0x3FFF

#define READ_CMD 0x4000

#define SS_PIN 9

void setup() {
  Serial.begin(9600);
  pinMode(SS_PIN, OUTPUT);
  SPI.begin();
  SPI.setDataMode(SPI_MODE1);
  SPI.setBitOrder(MSBFIRST);
}

void loop() {
  int angle = readAngle();
  Serial.print("Angle: ");
  Serial.println(angle);
  delay(500);
}

int readAngle() {
  digitalWrite(SS_PIN, LOW);
  uint16_t command = READ_CMD | ANGLE_REG;
  uint16_t result = SPI.transfer16(command);
  digitalWrite(SS_PIN, HIGH);
  result &= 0x3FFF;

  return result;
}

My friend wrote this code out for me but now I'm trying it out and I get no outputs. I tried this from what he wrote to see if I got any signal from it but nothing.

#include <SPI.h>

#define SS_PIN 9

void setup() {
  Serial.begin(9600);
  pinMode(SS_PIN, OUTPUT);
  SPI.begin();
  SPI.setDataMode(SPI_MODE1);
  SPI.setBitOrder(MSBFIRST);
  testSPICommunication();
}

void loop() {

}

void testSPICommunication() {
  digitalWrite(SS_PIN, LOW);
  uint16_t command = 0x0000;
  uint16_t result = SPI.transfer16(command);
  digitalWrite(SS_PIN, HIGH);
  if (result == 0xFFFF) {
    Serial.println("Signal");
  } else {
    Serial.println("No Signal");
  }
}

I checked the AS5127P has voltage and the connections to the other pins are fine I just get nothing from it no outputs of any kind.

What do you mean with "no output"? With that code you should see at least a serial output (twice per second) with an "Angle" value, so it could just be a wrong (or zero?) value, but I think you can't have "no outputs" at all. Please tell us what you see from serial.

Said that, I can't test it because at the moment I don't have any SPI device to test with (why do you use pin 9 for SS instead of the standard 53?) but I think you should try using a specific library like THIS. Give it a try.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.