Pages: [1]   Go Down
Author Topic: Can't get code to work on a Linux computer  (Read 392 times)
0 Members and 1 Guest are viewing this topic.
Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My program below works on a Windows computer. I moved it over to a Linux computer, though, and it won't work. Also, the version of Arduino IDE on the Windows computer is 22, while on the Linux computer it is 18. Finally, I had to put the Spi.h file in the avr/include folder on my Linux machine. I may not have done that correctly.

Code:
// include the SPI library:
#include <Spi.h>
#define potInputPin 5

// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
int potValue;

void setup() {
    // start serial port at 9600 bits per second
  Serial.begin(9600);

  // clear the serial port buffer
  Serial.flush();
// set the slaveSelectPin as an output:
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();
}

void loop() {

    for (int level = 0; level < 256; level = level + 1) {
      digitalPotWrite(0x00, level);
      Serial.print("  ");
      Serial.print(level);
      Serial.print("\t");     
      delay(100);
      potValue = analogRead(potInputPin);

      Serial.print("  ");
      Serial.print(potValue);
      Serial.print("\n");     
    }


int digitalPotWrite(int command, int value) {
  // take the SS pin low to select the chip:
  digitalWrite(slaveSelectPin,LOW);
  //  send in the value via SPI:
  SPI.transfer(command);
  SPI.transfer(value);

  digitalWrite(slaveSelectPin,HIGH);
}


The SPI.begin(); statement in the code is highlighted, and I get an error message:

error expected unqualified-id before '.' token 
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void setup() {
    // start serial port at 9600 bits per second
  Serial.begin(9600);

  // clear the serial port buffer
  Serial.flush();
You just set up serial communications, including creating the receive buffer. The first thing you do after that function returns is flush the newly created buffer.

Where do you suppose data in that buffer came from in the 62.5 nanoseconds it has existed?

Major changes to the SPI/spi class took place in one of the recent versions of the IDE. You should upgrade your linux computer to the latest version, rather than trying to piece-meal fix the older version.
Logged

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You just set up serial communications, including creating the receive buffer. The first thing you do after that function returns is flush the newly created buffer.

Where do you suppose data in that buffer came from in the 62.5 nanoseconds it has existed?

That Serial.flush(); code is left over from a previous program. Frankly, I did not even notice it. Thanks for alerting me to its sorry existence.

Major changes to the SPI/spi class took place in one of the recent versions of the IDE. You should upgrade your linux computer to the latest version, rather than trying to piece-meal fix the older version.

The program is running on a BeagleBoard, which has an ARM processor. Version 18 of the Arduino IDE comes from the package downloader, and works. Version 22 has to be installed specially, and does not work.

The SPI library did not seem to be in the Arduino IDE when it was installed. So I got the SPI library from the Playground. I suspect I did something wrong installing that. So I asked here. Apparently, no one here has had the same problem. I'll see what I can do on my own.
Logged

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I haven't found an answer. But at least I found someone with the exact same problem. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286741439

It does seem, as PaulS suggests, that if I could install Arduino IDE 22 that the problem would be solved. Try as I might, though, I can't get it to install. The error output in the terminal says something about the installation script not being able to find the right files.
Logged

Pages: [1]   Go Up
Jump to: