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.
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.
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?
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
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
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
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?
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
Aswinth Raj
PermalinkHave 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?
- Log in or register to post comments
Joined August 16, 2016 1000Tuesday at 12:29 AM