PS3 controller outputs to 0-5v signal and digital pot programming questions

I have successfully tried some simple sketches and the controller is communicating well with the Arduino uno rev3 I have.

I’m now trying to get a bit more difficult.

I want the PS3.getAnalogHat(LeftHatX) to turn on a output when the joystick is in a certain range.

Here’s my example code

#include <PS3USB.h>

USB Usb;
/* You can create the instance of the class in two ways */
PS3USB PS3(&Usb); // This will just create the instance
//PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

int LED = 3;

boolean printAngle;
uint8_t state = 0;

void setup() {
pinMode(LED, OUTPUT);
Serial.begin(115200);
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while (1); //halt
}
Serial.print(F("\r\nPS3 USB Library Started"));
pinMode(LED, OUTPUT);
}
void loop() {
Usb.Task();

if (PS3.PS3Connected || PS3.PS3NavigationConnected)
digitalWrite(LED, PS3.getAnalogHat(LeftHatX)= 120-155));
else
digitalWrite(LED, LOW);

}

Very simple but I get a Ivalue required as left operand of assignment

I know it’s not written correctly but I can’t find any examples out there for this project

Also know I'm asking to wite digital command from and analog input through the ps3 controller

I'm just asking for help with where to start on the code.

Second thing I want to do is take the other joystick Ps3.getAnalogHAt(LeftHatX)

And use the value 0-255 and convert that to an output either 0-5v using a (rc circuit or DAC chip I have the hardware just need a little help with the code interfacing with the ps3 controller) or 0-5k resistance using a digital pot. I need to figure out each way and try them to find out what will work best for this application.

Thanks,

digitalWrite(LED, PS3.getAnalogHat(LeftHatX)= 120-155));

You can't assign a value (-35) to a function.

You can do this:

int leftHatValue =  PS3.getAnalogHat(LeftHatX);

and then use leftHatValue... (Although assigning it a new value in the digitalWrite() call doesn't make sense.)

Also, using digitalWrite() in this context is wrong. It appears that you want analogWrite() to output a PWM value.

I can get this to work
int leftHatValue = PS3.getAnalogHat(LeftHatX);

It just works all the time. I'm just trying to get it to turn that digital output on only when PS3.getAnalogHat(LeftHatX) is in a certain range from 0-255. for example 120-155

I'm trying to get it to turn an input on when the joystick is moved from its neutral position.

I also need a way to say on the other joystick 0-255 value from the ps3 controller is linear with a pwm output on the arduino board. For example, if the joystick is at 150 pos then I want the pwm signal to be at the 150 count as well.
Not sure how the code looks to accomplish that.

Thanks for the help

I'm just trying to get it to turn that digital output on only when PS3.getAnalogHat(LeftHatX) is in a certain range from 0-255. for example 120-155

What are you trying?

Not sure how the code looks to accomplish that.

int otherJoystickValue = PS3.getOtherJoystickValue();
analogWrite(somePin, otherJoystickValue);

I'm pretty sure that this won't compile, but it should give you a hint at least.

I was able to get it to work by using this

digitalWrite(led1, PS3.getAnalogHat(RightHatX) > 160 ? 1 : 0);

I was also able to get the second one to work using

analogWrite(led, PS3.getAnalogHat(LeftHatY));

Now I just need to invert the above somehow so that for example 255count from controller = 0 count from pwm pin.
The above works so that 255 count from controller = 255 count from pwm pin

Hope this helps someone else out thats looking for this.

Thanks,
Derek

Use the map function,

map(value,fromlow ,fromhigh,tolow,tohigh)

To reverse scale set to low to the higher bound and to high to the lower bound. In your case .....255,0).

Use the map function,

Or, since the mapping ranges are the same, except that the order is reversed:

analogWrite(led, 255 - PS3.getAnalogHat(LeftHatY));

The above worked great and I thank you guys for that info.

One more question and I'm quite lost on this one. I'm trying to use the MCP4725 DAC chip on the I2C line to write a 0-5v output from the ps3 controller input from 0-255.

So I need a sample code or directions on how to set it up so that when ps3.getAnalogHat is say 127 the DAC needs to output about 2.5v or so.
basically make it so the DAC 0-5v outut follows the ps3 controller joystick movement from 0-256.

This is to control a motor drive a pg drives sigma drive to be exact. I tried a simple low pass filter on a pwm signal at 127 which read 2.5v or so on my meter. The reality is when I connected it to the drive it read 5v on the diag screeen on the drives programmer. It has a diag screen to tell what input and outputs it see's and sends. It must be picking up the 5v pulses even with the filter. The filter is 47uf and 47k resistor.

I'm giving up on the low pass filter in hopes a real 0-5v signal will be better to feed to the motor drive hence the question above

Thanks,

So I need a sample code or directions on how to set it up so that when ps3.getAnalogHat is say 127 the DAC needs to output about 2.5v or so.

First, you put the PS3 controller away. It has NOTHING to do with the issue of writing some value to the DAC to make it do something. Later, when you can write specific values to the DAC, and have it respond appropriately, you can get the PS3 controller back out, and use it to determine what value to write to the DAC,

Provide a link to the device you want to talk to, and a diagram showing how it is connected to the Arduino (and tell us which Arduino it is connected to).

First off I know the controller has nothing to do with the DAC.

I'm needing a way to map the controller joysticks movement to the correct I2C address to generate the correct 0-5v output from the adafruit MCP4725 DAC breakout.

I can generate the correct voltage if I write the adress in there but I need it to follow the joysitck movement so it keeps writing the correct address fr the joystick position.

I'm just using adafruits sample code but can't much farther than that.

The motor drive I'm trying to control is pg drives sigma drive. Attached is the wiring diagram. I'm going on pins 8 or 9 it needs to be a 0-5v signal that that circuit can recognize.

Depending if I go with the DAC or still a smoothed pwm signal that will work with that circuit will determine how I wire up the Arduino Uno I'm using.

I couldn't get my first low pass to work but now since you can see the internal circuit maybe you can help with a way to feed it a 0-5v analog signal.

Also ignore the pots this controller can take either a 2 or 3 wire pot or a 0-5v signal

Thanks,
Derek

sigma sem 554124477.xps (433 KB)

'm needing a way to map the controller joysticks movement to the correct I2C address

You're not even in the right forest. Forget about barking up the right tree. The chip has an I2C address. It's address makes no difference to what value you want it to output.

As I said, forget about getting it to output something from the controller. Get it to output something based on a constant, like 200. Then, make sure it outputs something different with a different constant, like 50. Then, make sure the output in both cases is what it should be, given the value you supplied.

And, I still don't see a link to the device. So, you're on your own. Good luck.

I'm not sure why you have to discredit me. I feel I'm close to at least the right forest maybe not the right tree :cold_sweat:

I was able to output 2.5v given the correct address of 0x07FF for uint16_t output

The address of I2C is 0x62.

All I needed was how to take that 0-0X0FFF that I send on the I2C to correspond to the controllers 0-255.

Also I sent the wiring diagram for the controller used. I just need way to get a 0-5v signal on that pin that the internal circuit will work with. Thats why I'm using a DAC because the low pass didnt seem to work.
below is the sigma drive I'm using and the model I have doesnt use pwm...wish it did.
It was originally setup as a wig-wag and I'm converting it to a 0-5v signal

http://www.pgdt.com/Products/Sigmadrive/Design-and-Functionality.aspx

Thats the controller I'm just trying to send it a 0-5v signal to control speed of the motor thats why I added the wiring diagram

Heres what I have so far

/**************************************************************************/
/*!

This is an example sketch for the Adafruit MCP4725 breakout board
----> https://www.adafruit.com/products/???

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include <Wire.h>
#include <Adafruit_MCP4725.h>
#include <PS3USB.h>

Adafruit_MCP4725 dac;

USB Usb;
/* You can create the instance of the class in two ways */
PS3USB PS3(&Usb); // This will just create the instance
//PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

boolean printAngle;
uint8_t state = 0;

void setup() {
Serial.begin(115200);
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while (1); //halt
}
Serial.print(F("\r\nPS3 USB Library Started"));

Serial.begin(9600);
Serial.println("Hello!");

// For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
// For MCP4725A0 the address is 0x60 or 0x61
// For MCP4725A2 the address is 0x64 or 0x65
dac.begin(0x62);

Serial.println("Generating a signal");
}

void loop() {

uint16_t output = map(PS3.getAnalogHat(LeftHatX), 0, 255, 0, 4095);

}

I do have two different baud rates because the ps3 is 115200 and the DAC is 9600 not sure if I can change them

Keep in mind I've only been around C++ for 2 weeks or so and trying to learn it.
Thanks,

I do have two different baud rates because the ps3 is 115200 and the DAC is 9600 not sure if I can change them

You said, in one post, that the DAC is a serial device and an I2C device. It isn't both. Or, rather, it might be but you choose ONE method to talk to it.

And, you seem to be trying to use one serial port to talk to the PS3 controller, the DAC, AND the PC. It can talk to ONE device. Which ONE do you want to talk to?

The DAC is on I2C
The PS3 controller is on SPI

are you saying I can't talk to both.

So example Ps3 Controller sends input to arduino for position of joystick
Arduino then reads posistion from PS3 controller over SPI
Arduino then sends address over I2C to DAC to output correct voltage.

Is that not possible?

Thanks,

The DAC is on I2C

Then, why are you talking about a serial baud rate to talk to it? Serial is not involved. So, any talk of baud rate is nonsense.

are you saying I can't talk to both.

I never said anything like that.

So example Ps3 Controller sends input to arduino

No, it doesn't. The data is read (pulled) by the Arduino. It is not pushed by the PS3 controller.

Arduino then sends address over I2C to DAC to output correct voltage.

No, it doesn't. It sends DATA to some address where it expects that a DAC lives.

Is that not possible?

Not using your improper terminology. But, what you want to do IS possible.

Ok did some reading and understand a bit more about the serial function

Now I tried this code and I know I'm missing something..just not sure what

So I tried this code

*/
/**************************************************************************/
#include <Wire.h>
#include <Adafruit_MCP4725.h>
#include <PS3USB.h>

Adafruit_MCP4725 dac;
USB Usb;
/* You can create the instance of the class in two ways */
PS3USB PS3(&Usb);

uint16_t output = map(PS3.getAnalogHat(LeftHatX), 0, 255, 0, 4095);

void setup(void) {
Serial.begin(9600);
Serial.println("Hello!");

// For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
// For MCP4725A0 the address is 0x60 or 0x61
// For MCP4725A2 the address is 0x64 or 0x65
dac.begin(0x62);

Serial.println("Generating a triangle wave");
}

void loop(void) {

dac.setVoltage(output, false);

}

I cant seem to get it to change with the controller. I know I'm missing something.

I do get 2.5v so the DAC is working.

Thanks,

uint16_t output = map(PS3.getAnalogHat(LeftHatX), 0, 255, 0, 4095);

Once, when the Arduino starts up, you read a value.

From then on, you write the same value to the DAC. Is that REALLY what you want?