Accelerometer ADXL 337 inputing to Arduino Uno and outputting to serial port (processing)

Rick H. William's picture

Offline

Joined: Nov 27, 2019

Replies: 6
Accelerometer ADXL 337 inputing to Arduino Uno and outputting to serial port (processing)
November 27, 2019 - 11:56am

I have been working on a project similar to this https://circuitdigest.com/microcontroller-projects/ping-pong-game-using-arduino-accelerometer#comment-30863

I am having problems with reading my values from my accelerometer on processing. It is making my paddle shake essentially because the values that the serial is reading is 140, 141, 57, 58 and so on in that continous pattern. Is there anything I can so that the values are more consistently read by processing? I already implemented a smooth function in my arduino code that eliminates the highest and lowest values and takes the average of the measurements.

Aswinth Raj's picture

Offline

Joined: Aug 16, 2016

Replies: 943
I think your values are not real
November 28, 2019 - 10:58am

Have you considered that processing does not read serial values as int but as ascii. I would recommend you to read the tutorial you have provided to understand this.

Because when Arduino sends a value, say for example the X value from accel is 120. This 120 will be read as 49 50 48 becasue the acii value of 1 2 and 0 is 49 50 and 48. You should try printing the accel values on Arduino serial port and compare the same on processing IDE to check if both are same 

Also the Accelerometer can give you only X,Y and Z how did you get this 140, 141, 57, 58?

Rick H. William's picture

Offline

Joined: Nov 27, 2019

Replies: 6
 while (myPort.available () >
November 29, 2019 - 11:41pm

 while (myPort.available () > 0) { // make sure port is open
 DataValues = myPort.read();
 AccelReading = int(map(float(DataValues), 0, 255, 30, 1170));
 println(AccelReading);  //****// 

 

This is my processing code, I made sure that the values are mapped out over the size of the screen AND to be an integer. The value that is being read on the processing code is just so jittery. It seems that the smooth function in arduino isnt working. Ive tried to increase/decrease the filter number and it doesnt help. Ive also increased the Baud rate to increase the speed of communication and that hasnt help either. 

Rick H. William's picture

Offline

Joined: Nov 27, 2019

Replies: 6
I figured it out, it was a
November 30, 2019 - 2:52am

I figured it out, it was a mistake on my part the values were not being read correctly. However whenever I save the processing code to my desktop, the balls deflection does not work. Could there be a possibility of saving the arduino and processing codes in different folders make it difficult for them to communicate? 

Aswinth Raj's picture

Offline

Joined: Aug 16, 2016

Replies: 943
Saving in different folder will not be a problem
November 30, 2019 - 9:43am

Hi Rick, glad you found the problem. But saving the code to your desktop should not stop the program from working. What error does your processing code show? When you say something does not work in a forum please explain your problem to help people solve it.

Make sure you have used the correct COM port number in the processing code. If you change your USB port your COM port will also chage 

Rick H. William's picture

Offline

Joined: Nov 27, 2019

Replies: 6
How to add another ball in processing
December 2, 2019 - 3:08am

I saw in your video that you were able to add a ball to the screen, I am trying to add a ball to the screen when a button is pushed down (signaled by the arduino and sent to processing). I was able to write code where processing knows when the button is pushed, but im having problems with the code in proccessing. Could you PLEASE help me with anything you know? I am REALLY struggling

Rick H. William's picture

Offline

Joined: Nov 27, 2019

Replies: 6
Aswinth, Sorry about not
December 1, 2019 - 9:10am

Aswinth, Sorry about not explaining. When the processing code is ran, the ball proceeds down to the paddle and when the ball and paddle make contact with each other, the ball is stuck for a short amount of time and then is shot out to the right or left at a 90 degree angle. once the ball hits the wall it is then stuck to the wall

Rick H. William's picture

Offline

Joined: Nov 27, 2019

Replies: 6
Well now it is working, not
December 1, 2019 - 9:20am

Well now it is working, not sure why it wasnt. Could you give me any advise on how to make the paddle movement more smoother during the game? Would increasing the filter size in arduino help?

Aswinth Raj's picture

Offline

Joined: Aug 16, 2016

Replies: 943
smoothness depends on the sensor capability
December 2, 2019 - 12:48pm

Using a better sensor like MPU 6050 will help. Yes you can also play with the filter values, but it wont help much. There are many algorithms to smooth sensors values you can also check them out