Esempio n. 1
0
int main(){
   cout << "Starting the RPi MAX7219 example" << endl;
   SPIDevice *max = new SPIDevice(0,1);
   max->setSpeed(10000000);              // max speed is 10MHz
   max->setMode(SPIDevice::MODE0);

   // turn on the display and disable test mode -- just in case:
   max->writeRegister(0x0C, 0x01);
   max->writeRegister(0x0F, 0x00);
   max->writeRegister(0x0B, 0x07);       // set 8 digit mode
   max->writeRegister(0x09, 0xFF);       // set decode mode on all

   for(int i=1; i<9; i++){
      max->writeRegister((unsigned int)i, 0x0A); // clear to dashes
   }

   for(int i=0; i<=100000; i++){
      int val = i;
      unsigned int place = 1;
      while(val>0){
        max->writeRegister( place++, (unsigned char) val%10);
        val = val/10;
      }
//    usleep(1000);
   }
   max->close();
   cout << "End of the RPi MAX7219 example" << endl;
   return 0;
}
Esempio n. 2
0
int main(){
   cout << "Starting EBB SPI ADC Example" << endl;
   SPIDevice *busDevice = new SPIDevice(1,0); //Using second SPI bus (both loaded)
   busDevice->setSpeed(400000);      // Have access to SPI Device object
   busDevice->setMode(SPIDevice::MODE0);

   unsigned char send[3], receive[3];
   send[0] = 0b00000110; // The Start Bit followed
   // Set the SGL/Diff and D mode -- e.g., 1000 means single ended CH0 value
   send[1] = 0; // The MSB is the Single/Diff bit and it is followed by 000 for CH0
   send[2] = 0;          // This byte doesn't need to be set, just for a clear display
   busDevice->transfer(send, receive, 3);
   cout << "Response bytes are " << (int)receive[1] << "," << (int)receive[2] << endl;

   // Use the 8-bits of the second value and the two LSBs of the first value
   int value = combineValues(receive[1]&0b00001111, receive[2]);
   cout << "This is the value " << value << " out of 4096." << endl;
   cout << "End of EBB SPI ADC Example" << endl;
}
Esempio n. 3
0
int main(){
   SPIDevice *busDevice = new SPIDevice(1,0); //Using second SPI bus (both loaded)
   busDevice->setSpeed(4000000);      // Have access to SPI Device object
   busDevice->setMode(SPIDevice::MODE0);

   unsigned char send[3], receive[3];
   int samples[SAMPLES];

   send[0] = 0b00000001; // The Start Bit followed
   // Set the SGL/Diff and D mode -- e.g., 1000 means single ended CH0 value
   send[1] = 0b10000000; // The MSB is the Single/Diff bit and it is followed by 000 for CH0
   send[2] = 0;          // This byte doesn't need to be set, just for a clear display

   for(int i=0; i<SAMPLES; i++){
   	busDevice->transfer(send, receive, 3);
        samples[i] = (short((receive[1]&0b00000011))<<8)|(short(receive[2]));
   }
   for(int i=0; i<SAMPLES; i++){
        cout << i << " " << samples[i] << endl;
   }
}
Esempio n. 4
0
/*
 * Start the plugin
 * For now we just have one device.
 */
bool SPIPlugin::StartHook() {
  const string uid_str = m_preferences->GetValue(SPI_BASE_UID_KEY);
  auto_ptr<UID> base_uid(UID::FromString(uid_str));
  if (!base_uid.get()) {
    OLA_WARN << "Invalid UID " << uid_str << ", defaulting to "
             << DEFAULT_BASE_UID;
    base_uid.reset(UID::FromString(DEFAULT_BASE_UID));
    if (!base_uid.get()) {
      OLA_WARN << "Invalid UID " << DEFAULT_BASE_UID;
      return false;
    }
  }

  vector<string> spi_files;
  vector<string> spi_prefixes = m_preferences->GetMultipleValue(
      SPI_DEVICE_PREFIX_KEY);
  if (!ola::file::FindMatchingFiles("/dev", spi_prefixes, &spi_files)) {
    return false;
  }

  ola::rdm::UIDAllocator uid_allocator(*base_uid);
  vector<string>::const_iterator iter = spi_files.begin();
  for (; iter != spi_files.end(); ++iter) {
    SPIDevice *device = new SPIDevice(this, m_preferences, m_plugin_adaptor,
                                      *iter, &uid_allocator);

    if (!device) {
      continue;
    }

    if (!device->Start()) {
      delete device;
      continue;
    }
    m_devices.push_back(device);
    m_plugin_adaptor->RegisterDevice(device);
  }
  return true;
}
Esempio n. 5
0
int main(){
//   cout << "Starting RPi SPI ADC Multi Example" << endl;
   SPIDevice *busDevice = new SPIDevice(0,0); //Using second SPI bus (both loaded)
   busDevice->setSpeed(3900000);      // Have access to SPI Device object
   busDevice->setMode(SPIDevice::MODE0);

   unsigned char send[3], receive[3];
   int samples[SAMPLES];

   send[0] = 0b00000001; // The Start Bit followed
   // Set the SGL/Diff and D mode -- e.g., 1000 means single ended CH0 value
   send[1] = 0b10000000; // The MSB is the Single/Diff bit and it is followed by 000 for CH0
   send[2] = 0;          // This byte doesn't need to be set, just for a clear display

   for(int i=0; i<SAMPLES; i++){
   	busDevice->transfer(send, receive, 3);
        samples[i]=combineValues(receive[1]&0b00000011, receive[2]);
   }
//   cout << "The samples that were captured are:" << endl;
   for(int i=0; i<SAMPLES; i++){
        cout << i << " " << samples[i] << endl;
   }
//   cout << "\nEnd of RPi SPI ADC Example" << endl;
}