Arduboy Accelerometer


#21

…would you be able to post the code for these experiments?

…pleeeeeease? :grin:


ArduBreakout on a watchX
(Scott R) #22

Sorry for the delay I’ve been away from a PC for some time. Here’s the basic gist of things i’ll get some full examples and links posted once I’ve had time to check licences and what not.

#include <Wire.h>

//MPU
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

setup()

  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);

loop()

{
  // pause render until it's time for the next frame
  if (!(arduboy.nextFrame()))
    return;

  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(true);
  Wire.requestFrom(MPU,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)    
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)

for inputs

void movePaddle()
{
  //Move right
  if(xPaddle < WIDTH - 12)
  {
    if (arduboy.pressed(RIGHT_BUTTON))
    {
      xPaddle+=2;
    }
  }

would become

void movePaddle()
{
  //Move right
  if(xPaddle < WIDTH - 12)
  {
    if (AcY < -2500)
    {
      xPaddle+=2;
    }

Depending on orientation you X & Y’s may reverse and you would need to adjust the value depending on how much sensitivity or turn you want for each direction.

The wiring is self explanatory VCC GND SCL SDA I am not using the INT pin you may find that the accelerometer will hang at times this is due to a bug in Wire.h there’s apparently a modified version that resolves it but I’ve not had time to look into it. I found that for some games that hang adding a delay in setup will give the accelerometer a chance to settle.

Oh and dont forget to enable I2C in the Arduboy2 library this had me stumped for some time when I couldn’t figure out why the device wasnt working :stuck_out_tongue:

In Arduboy2Core.cpp

void Arduboy2Core::bootPowerSaving()
{
  // disable Two Wire Interface (I2C) and the ADC
  // All other bits will be written with 0 so will be enabled
  PRR0 = _BV(PRTWI) | _BV(PRADC);
  // disable USART1
  PRR1 |= _BV(PRUSART1);
}

becomes

void Arduboy2Core::bootPowerSaving()
{
  // disable Two Wire Interface (I2C) and the ADC
  // All other bits will be written with 0 so will be enabled
  PRR0 = _BV(PRADC);
  // disable USART1
  PRR1 |= _BV(PRUSART1);
}

(Scott R) #23

https://github.com/KeyboardCamper/A-Maze/tree/master/A-Maze-AB-MPU6050

I also modified the cube code here http://cyaninfinite.com/tutorials/mpu6050-and-3d-cube/#Code
i’ll post it once I find where I put it…

Edit: this should be it


ArduBreakout on a watchX
#24

Got it - thanks!! :grinning:

I modified A-Maze to run on the Micro:Gamer I was lucky enough to receive - using the micro:bit’s accelerometer:


#25

(Pharap) split this topic #32

5 posts were merged into an existing topic: ArduBreakout on a watchX


#33

Fabien has put up a small batch of Micro:Gamer boards on Tindie:


(Simon) #34

Was I surprised to see that ‘Dark and Under’ is available ‘out of the box’ !


#35

…you shouldn’t be surprised :wink:


(Pharap) #36

The name Fabien Chouteau was the giveaway for me.

I’m disappointed that the ported Minesweeper is the other Minesweeper. ; n ;
(Maybe he couldn’t figure out how my save system works?)


(Simon) #37

I (obviously) knew someone had ported it to this platform but I wasn’t aware they were ‘reselling’ it.

Have you encountered him before?


(Pharap) #38

What do you mean ‘reselling’?
Fabien Chouteau is the one who created the MicroGamer.
He’s the only seller.

Back when D&U was ported, it was still in the early stages and wasn’t commercially available.

Yes, when you made the post that @uXe just linked to,
I dug around and found his D&U fork.

“MicroGamerConsole” is an organisation, and although it has no public members it’s pretty clear that Fabien Chouteau is a member because he’s the only one who committed to the D&U fork after it being forked:

At the time I thought D&U being ported to a console I’d never heard of warranted some investigation.
(Making sure the licence isn’t being violated, etc.)

I think it’s a bit odd that his ownership of the MicroGamerConsole organisation isn’t public, but it’s easy enough to prove his connection, so it’s not exactly hidden either.
I’m guessing he’s trying to keep it separate from his work stuff for some reason.


(Simon) #39

As you say, there is an organisation called MicroGamerConsole profiting from the sale of the units. He isn’t selling the games (hence the inverted commas around the word ‘reselling’) but is using the as part of his selling material.

He isn’t breaking any licence agreements as far as I can tell but …


(Pharap) #40

An organisation of (presumably) just one person.

Unless the games are being loaded onto the console before sale, they’re not being sold at all.
And there aren’t any open source licences that prohibit profiting from the code anyway,
so theoretically he could sell the games directly and there would still be no legal issue as long as the origin of the games weren’t misrepresented and any licence-specific clauses were followed.

For the BSD 3-clause, the licence only has to be included in the documentation,
so theoretically a game could be forked, close-sourced and sold as long as the licence is kept in the game documentation.

Unfortunately there’s no open source licence that prevents selling the code, and the ones that force the code to stay completely open source tend to have other issues (like the GPL’s ‘virus clause’).


(Simon) #41

Correct - as he is not even providing the MicroBit itself. However, interesting words ‘There are 11 games available out of the box …’ which implies that he is selling the device and the games together. Its simply a bad choice of words as we know he is providing the source (legally) and asking users to compile and load them themselves.