Recent Posts

Pages: 1 ... 6 7 [8] 9 10
71
I use CC1101 433MHz RF-module with PanStamp library to make a 2 way communication.

I have finished transmitting and receiving the data, like in the code below:

Transmitting:
 
Code: [Select]
#include <cc1101.h>
#include <EEPROM.h>
#include <Wire.h>
#include <PS2X_lib.h>

// Create a objekct
CC1101 cc1101;

PS2X ps2x;


// VARIABELS
int error = 0;
byte type = 0;
 
// counter to get increment in each loop
byte counter;
byte b;
byte syncWord = 199;
 
 
void setup()
{
Serial.begin(9600);

error = ps2x.config_gamepad(9,8,7,6, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error

  if(error == 0){
   Serial.println("Found Controller, configured successful");
  }
 
  else if(error == 1)
   Serial.println("No controller found, check wiring.");
   
  else if(error == 2)
   Serial.println("Controller found but not accepting commands.");
   
  else if(error == 3)
   Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
 
  type = ps2x.readType();
     switch(type) {
       case 0:
        Serial.println("Unknown Controller type");
       break;
       case 1:
        Serial.println("DualShock Controller Found");
       break;
     }

Serial.println("starter RF");
 
 
// reset the counter
counter=0;
Serial.println("initializing...");
// initialize the RF Chip
cc1101.init();
 
cc1101.setSyncWord(&syncWord, false);
cc1101.setCarrierFreq(CFREQ_433);
cc1101.disableAddressCheck();
//cc1101.setTxPowerAmp(PA_LowPower);
 
delay(1000);
 
Serial.print("CC1101_PARTNUM "); //cc1101=0
Serial.println(cc1101.readReg(CC1101_PARTNUM, CC1101_STATUS_REGISTER));
Serial.print("CC1101_VERSION "); //cc1101=4
Serial.println(cc1101.readReg(CC1101_VERSION, CC1101_STATUS_REGISTER));
Serial.print("CC1101_MARCSTATE ");
Serial.println(cc1101.readReg(CC1101_MARCSTATE, CC1101_STATUS_REGISTER) & 0x1f);
 
Serial.println("device initialized");
//Serial.println("done");
}

void loop()
{

ps2x.read_gamepad(false, false);          //read controller and set large motor to spin at 'vibrate' speed
 
CCPACKET data;
data.length=1;
//byte data = 0;
if(ps2x.ButtonPressed(PSB_RED)){             //will be TRUE if button was JUST pressed
         Serial.println("Circle just pressed");
        data.data[0] = 20;
        Serial.println(data.data[0]);
        cc1101.sendData(data);
       
}
else if(ps2x.ButtonReleased(PSB_RED)){             //will be TRUE if button was JUST released
         Serial.println("Circle just released");
        data.data[0] = 0;
        Serial.println(data.data[0]);
        cc1101.sendData(data);
}

}

   
Receiving:

Code: [Select]
#include <Wire.h>
#include <EEPROM.h>
#include "cc1101.h"
 
 
// The connection to the hardware chip CC1101 the RF Chip
CC1101 cc1101;


int j;
byte x;
byte b;
byte i;
byte syncWord = 199;
long counter = 0;
byte chan = 0;
 
// a flag that a wireless packet has been received
boolean packetAvailable = false;
 

 
/* Handle interrupt from CC1101 (INT0) gdo0 on pin2 */
void cc1101signalsInterrupt(void) {
  // set the flag that a package is available
  packetAvailable = true;
}
 
void setup()
{
 
  Wire.begin();

  Serial.begin(9600);
  Serial.println("start");
   
 
  // initialize the RF Chip
  cc1101.init();
 
  cc1101.setSyncWord(&syncWord, false);
  cc1101.setCarrierFreq(CFREQ_433);
  cc1101.disableAddressCheck(); //if not specified, will only display "packet received"
  //cc1101.setTxPowerAmp(PA_LowPower);
 
  Serial.print("CC1101_PARTNUM "); //cc1101=0
  Serial.println(cc1101.readReg(CC1101_PARTNUM, CC1101_STATUS_REGISTER));
  Serial.print("CC1101_VERSION "); //cc1101=4
  Serial.println(cc1101.readReg(CC1101_VERSION, CC1101_STATUS_REGISTER));
  Serial.print("CC1101_MARCSTATE ");
  Serial.println(cc1101.readReg(CC1101_MARCSTATE, CC1101_STATUS_REGISTER) & 0x1f);
 
  attachInterrupt(0, cc1101signalsInterrupt, FALLING);
 
  Serial.println("device initialized");
 
}
 
void ReadLQI()
{
  byte lqi = 0;
  byte value = 0;
  lqi = (cc1101.readReg(CC1101_LQI, CC1101_STATUS_REGISTER));
  value = 0x3F - (lqi & 0x3F);
  Serial.print("CC1101_LQI ");
  Serial.println(value);
}
 
void ReadRSSI()
{
  byte rssi = 0;
  byte value = 0;
 
  rssi = (cc1101.readReg(CC1101_RSSI, CC1101_STATUS_REGISTER));
 
  if (rssi >= 128)
  {
    value = 255 - rssi;
    value /= 2;
    value += 74;
  }
  else
  {
    value = rssi / 2;
    value += 74;
  }
  Serial.print("CC1101_RSSI ");
  Serial.println(value);
}
 
void loop()
{
  if (packetAvailable) {
    Serial.println("packet received");
    // Disable wireless reception interrupt
    detachInterrupt(0);
 
    ReadRSSI();
    ReadLQI();
    // clear the flag
    packetAvailable = false;
 
    CCPACKET packet;
 
    if (cc1101.receiveData(&packet) > 0) {
      if (!packet.crc_ok) {
        Serial.println("crc not ok");
       
      }
     
      else if (packet.crc_ok){
      if (packet.length > 0) {
        Serial.print("packet: len ");
        Serial.print(packet.length);
        Serial.print(" data: ");

        j = 0;
        x = packet.data[j];
          Serial.print(x);
          Serial.print(" ");
          Wire.beginTransmission(4);// transmit to device #4
          Wire.write(x);              // sends one byte 
          Wire.endTransmission();    // stop tran
        Serial.println(".");
       
      }
    }
    }
    // Enable wireless reception interrupt
    attachInterrupt(0, cc1101signalsInterrupt, FALLING);
  }

}


The CC1101 is a half-duplex type architecture. It cannot transmit while receiving, however it can switch between transmit and receive very quickly.

Then my question is should I implement a Chip Select to be able to communicate as transceiver? If yes, do you have please some idea how to do it? I,m pretty blank.

72
Programming Questions / Re: Difference between uint8_t...
Last post by KenF - Today at 02:02 am
Quote
Also 'uid' works just find instead of &uid[0].
When you have an array, the variable is actually a pointer.

so  This creates a char variable called x
Code: [Select]

char x="y";


BUT This reserves some space for 11 chars creates a char pointer called z that is initialised to point to that array
Code: [Select]

char z[11]="0123456789";


so if you have function that wants a char pointer and had implemented these two examples, you could pass
either &x (the address of the character 'y')
or
z (this is already holding the address of the character '0' so we don't need the &

73
Bar Sport / Re: A step back in time
Last post by Graynomad - Today at 02:01 am
Yes data books are pretty much a thing of the past, I used to have 100s.

BTW, the forum is not longer notifying of new posts, I just re-found this thread by accident, so I'm guessing there won't be as many responses to all threads from now on unless that gets fixed.

______
Rob
74
General Electronics / Re: Does a pin act as a ground...
Last post by MarkT - Today at 01:59 am
Open is ambiguous - open-circuit means off, disconnected, but an open tap is on, connected.

Try to always say "on" or "off" for transistors and other switching devices, "open" and "closed"
are interpreted differently according to native tongue and context (an open switch is off, an
open valve is on, for instance, but if you speak English as a second language this distinctiion
is not obvious!

The reason for this is the original switches were knife-blade switches where you open the
gap between conductors, or closed the gap.  An open gap is no current flow, closed is current
flow.  In a valve for liquids open means the pipe is open (liquid can flow).

So "on" and "off" are better words to use here with an international audience.
75
Bar Sport / Re: Forum Upgrade
Last post by Graynomad - Today at 01:59 am
Not to me, you should only see your own, everyone else see "IP: logged"

______
Rob
76
Quote
CrossRoads "Arduino" inspired designs. Need something custom? Contact  robert@crossroadsfencing.com  

Modeled after the Solarbotics Ardweeny, but adapted to have the 1284P on wirewrap socket headers instead of sitting under a board and having to solder all the legs to something.  Killed your chip? Pop in a new one!
Header for offboard FTDI Module (can be right angle or vertical), "L LED at the edge of the board. Cuttable traces for Vcc from FTDI, DTR from FTDI, and for the L LED if you don't want a light.
$21.25 plus $5.25 USPS shipping to US addresses; international shipping is usually more.
$7.50 extra for an FTDI module - the one I use has a micro USB connector.
paypal to cardinalflyer at comcast dot net.

Schematic & Layout

77
Portugues / Re: DHT22 - Arduino Modbus
Last post by wmaldonadojr - Today at 01:56 am
Boa noite Pessoal!

Tentei algumas outras alternativas após a dica do float que o bubulindo me forneceu e consegui fazer funcionar, para isso separei em blocos e para cada ação eu chamo um bloco específico para realiza-la, segue abaixo a programação resumida:


Code: [Select]
#include "DHT.h"
/* DEFINIÇÃO DE CONEXÕES E PARÂMETROS */
/* CONFIGURAÇÃO  */
#define NUM_SAMPLES 50
#define DHTTYPE DHT22
//DEFINIÇÃO DE PINOS DE LEITURA DIGITAL
#define DHTPIN 3
DHT dht(DHTPIN, DHTTYPE);

void configure_mb_slave(long baud, char parity, char txenpin);
int update_mb_slave(unsigned char slave, int *regs, unsigned int regs_size);

/* PARÂMETROS MODBUS RTU DE COMUNICAÇÃO, O MESTRE E OS ESCRAVOS DEVEM USAR OS MESMOS PARÂMETROS */
enum {
 COMM_BPS = 9600, /* BAUD RATE */
 MB_SLAVE = 1, /* ENDEREÇO DO ESCRAVO MODBUS */
 PARITY = 'n', /* PARIDADE */
 TXEN = 0 /* DEFINIÇÃO DO PINO USADO PARA COLOCAR O DRIVER */
};
/* DEFINIÇÃO ORDENADA DE TODOS OS REGISTROS DE LEITURA E ESCRITA DA COMUNICAÇÃO ENTRE O MESTRE E O ESCRAVO (SCADA E ARDUINO) */
enum {
 SENSOR_UMIDADE, /* REGISTRADOR DO SENSOR DE LUMINOSIDADE */
 SENSOR_TEMPERATURA, /* REGISTRADOR DO SENSOR DE TEMPERATURA */
 MB_REGS /* NUMERO TOTAL DE REGISTRO DO ESCRAVO */
};
int regs[MB_REGS]; /* MAPA MODBUS DO SLAVE */

enum enum_estado{
  INICIO,
  ES_TEMPERATURA,
  ES_UMIDADE,
} ESTADO;

void setup()
{
 /* CONFIGURAÇÃO DA COMUNICAÇÃO MODBUS: 9600 BPS, 8N1, RS485 NETWORK */
 configure_mb_slave(COMM_BPS, PARITY, TXEN);
}
void loop()
{
  switch(ESTADO) {
  case ES_TEMPERATURA: {
     BLOCO_TEMPERATURA();
     break;
    }
    case ES_UMIDADE: {
     BLOCO_UMIDADE();
     break;  
  }  
/* VERIFICA SE HÁ SOLICITAÇÃO DO MESTRE - PARA TODOS OS SLAVES*/
  update_mb_slave(MB_SLAVE, regs, MB_REGS);
}
}
void BLOCO_INICIO(){
  ESTADO = ES_TEMPERATURA;
}
void BLOCO_TEMPERATURA(){
  float DHTtemperature = 0;
  DHTtemperature = dht.readTemperature();
  float TEMP = DHTtemperature * 10;
  regs[SENSOR_TEMPERATURA]= TEMP;
  ESTADO = ES_UMIDADE;
}
void BLOCO_UMIDADE(){
  float DHThumidity;
  DHThumidity = dht.readHumidity();
  float UMID = DHThumidity * 10;
  regs[SENSOR_UMIDADE]= UMID;
  ESTADO = INICIO;
}


Em anexo coloquei a programação completa com a programação do Modbus e com comentários.

Agradeço a ajuda e colaboração de todos!
Obrigado,
William Maldonado
78
It seems so, see here

http://forum.arduino.cc/index.php?topic=273614.150

starting at post #163

______
Rob
79
Arduino Yún / Re: Interface barcode scanner ...
Last post by sonnyyu - Today at 01:54 am
If I were you, I will connect ethernet  cable between router and Yun.
80
The system is mistaken, that's the most likely option at present. Until a couple of days ago we all had similar messages.

______
Rob
Pages: 1 ... 6 7 [8] 9 10