Pages: [1]   Go Down
Author Topic: Code help  (Read 539 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
I am currently working on a Tricorder project. I am going to use the Nunchuck for navigation and multiple sensors for input. The output will be the 5110 Nokia lcd. I am following the library and code from Adafruit for the LCD and following Wayne and Laynes Nunchuck code and library for the Nunchuck. Being a big noob I was having trouble combining the current sketch I have for printing sensor values to the LCD and the example Nunchuck code. My problem I think is because of the #include and #define lines of code.
here is the code for my sensor values
Code:
/*********************************************************************


#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2

#include <Wire.h>
#include <Adafruit_MPL115A2.h>


Adafruit_MPL115A2 mpl115a2;


void setup()   {               
  Serial.begin(9600);
  mpl115a2.begin();
  display.begin();
  // init done
 
  pinMode(13, OUTPUT);
  // you can change the contrast around to adapt the display
  // for the best viewing!
  display.setContrast(50);
 
  display.display(); // show splashscreen
  delay(2000);
  display.clearDisplay();   // clears the screen and buffer
 
  // Tricorder
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.println("Tricorder");
  display.display();
  display.clearDisplay();   // clears the screen and buffer
  delay(2000);
 
  // text display tests
  display.setTextSize(0.1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.println("Getting       temperature   and barometricpressure: ");
  display.display();
  display.clearDisplay();
  delay(2000);
   
 
 

  // invert the display
  display.invertDisplay(true);
  delay(1000);
  display.invertDisplay(false);
  delay(1000);
}
void loop(){

float pressureKPA = 0, temperatureC = 0;
  pressureKPA = mpl115a2.getPressure();
  temperatureC = mpl115a2.getTemperature();
  display.setTextSize(0.1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.println("Temp (*C): ");
  display.setTextSize(0.1);
  display.setTextColor(BLACK);
  display.println(temperatureC, 1);
  display.setTextSize(0.1);
  display.setTextColor(BLACK);
  display.setCursor(0,16);
  display.println("Barometric Pressure (*KPA): ");
  display.setTextSize(0.1);
  display.setTextColor(BLACK);
  display.println(pressureKPA, 1);
  display.display();
  display.clearDisplay();
  delay(2000);
 
  digitalWrite(13, HIGH);
  delay(10);
  digitalWrite(13, LOW);
}
void testdrawchar(void) {
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);

  for (uint8_t i=0; i < 168; i++) {
    if (i == '\n') continue;
    display.write(i);
    //if ((i > 0) && (i % 14 == 0))
      //display.println();
  }   
  display.display();
}
and here is the Nunchuck code
Code:
/*
   Arduino sketch to demonstrate interfacing with a Nintendo Wii Nunchuck. It will print the nunchuck information from P1 every second, to the serial terminal at 9600 baud.
   Created by Adam Wolf and Matthew Beckler
   Wayne and Layne, LLC - http://wayneandlayne.com/projects/video-game-shield/
   Recent updates:
        August 18, 2012 - Changed file extension to .ino for Arduino 1.0

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program; if not, write to the Free Software Foundation, Inc.,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

*/

#include <i2cmaster.h>
#include <nunchuck.h>

Nunchuck nunchuck;

void setup()
{
  nunchuck.begin(NUNCHUCK_PLAYER_1);
  Serial.begin(9600);
}

void loop()
{
  nunchuck.update();
  Serial.println("Nunchuck values:");
  Serial.println("Joystick:"); 
  Serial.print("x: "); Serial.println(nunchuck.joy_x(), DEC);
  Serial.print("y: "); Serial.println(nunchuck.joy_y(), DEC);
 
  Serial.println("Accelerometer:");
  Serial.print("x: "); Serial.println(nunchuck.acc_x(), DEC);
  Serial.print("y: "); Serial.println(nunchuck.acc_y(), DEC);
  Serial.print("z: "); Serial.println(nunchuck.acc_z(), DEC);

  Serial.println("Buttons:");
 
  Serial.print("c: ");
  if (nunchuck.button_c())
  {
    Serial.println("pushed");
  }
  else
  {
    Serial.println("not pushed");
  }
 
  Serial.print("z: ");
  if (nunchuck.button_z())
  {
    Serial.println("pushed");
  }
  else
  {
    Serial.println("not pushed");
  }
 
  delay(1000);
}
If somebody could give me the code before VoidSetup I think I could figure out the rest.
Thanks for the help   
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8842
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think your problem is that the Wire (I2C/TWI) library and the i2cmaster library both want control of the I2C/TWI hardware.

The "WiiChuck" library is compatible with the Wire library so if you use that instead of "nunchuck" you should be in better shape.

http://www.arduino.cc/playground/Main/WiiChuckClass
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: