Recent Posts

Pages: [1] 2 3 ... 10
1
Project Guidance / Re: How to FS3x to Due via TRS...
Last post by ZagatoZee - Today at 05:56 pm
Thank you blh64, that helps with the code portion I was wondering about and seems like it'll be more than easy enough to implement.

I didn't include this before since I was trying to avoid clutter, but I think my code is already covering the button and pull up issues you mention.

Code: [Select]

/* ZagatoZee 2 button control of iRotate commands for my secondary monitor.
ctrl+shift+left to rotate 90 degrtees to portrait, ctrl+shift+up for normal landscape
The circuit:
  - pushbutton attached from pin 4(etc) to +5V
  - 10 kilohm resistor attached from pin 4 to ground
*/

#include "Keyboard.h"

const int buttonPin4 = 4;          // input pin for pushbutton
const int buttonPin6 = 6;          // input pin for pushbutton
char ctrlKey = KEY_LEFT_CTRL;     // adds ctrl key
char shiftKey = KEY_LEFT_SHIFT;   // adds shift key
char leftKey = KEY_LEFT_ARROW;    // adds left arrow
char upKey = KEY_UP_ARROW;        // adds up arrow

void setup() {
  // make the pushButton pins inputs:
   pinMode(buttonPin4, INPUT_PULLUP);
   pinMode(buttonPin6, INPUT_PULLUP);
  // initialize control over the keyboard:
  Keyboard.begin();
}
void loop(){
    while (digitalRead(4) == LOW) {
    // do nothing until pin 4 goes HIGH
    delay(10);
    }
    delay(10);
    // rotate to portrait mode:
  Keyboard.press(ctrlKey);
  Keyboard.press(shiftKey);
  Keyboard.press(leftKey);
  delay(50);
  Keyboard.releaseAll();


while (digitalRead(6) == LOW) {
    // do nothing until pin 5 goes HIGH
    delay(10);
}
  delay(10);
  // rotate to landscape mode:
  Keyboard.press(ctrlKey);
  Keyboard.press(shiftKey);
  Keyboard.press(upKey);
  delay(50);
  Keyboard.releaseAll();
}


I'm still trying to get my head around the wiring needed on the Due side of the TRS cable, since the requirement of the 10kohm resistors on the switched side but before the connection to ground is complicating things (at least in my head) if trying to use the FS3x as is.
2
Français / Re: Problème fonctionnement le...
Last post by J-M-L - Today at 05:56 pm
vous alimentez comment vos LEDs?
3
As I said in my post I do apologise for the no code. Im using pull up resistors of 10kOhm on 5V Vcc for the SDA and SCL.

ATTiny Code
Code: [Select]
/*
// I2C
arduino pin 0 = not(OC1A) = PORTB <- _BV(0) = SOIC pin 5 (I2C SDA, PWM)
arduino pin 2 =           = PORTB <- _BV(2) = SOIC pin 7 (I2C SCL, Analog 1)
// Timer1 -> PWM
arduino pin 1 =     OC1A  = PORTB <- _BV(1) = SOIC pin 6 (PWM)
arduino pin 3 = not(OC1B) = PORTB <- _BV(3) = SOIC pin 2 (Analog 3)
arduino pin 4 =     OC1B  = PORTB <- _BV(4) = SOIC pin 3 (Analog 2)
*/
// Get this from https://github.com/rambo/TinyWire
#include "TinyWireS.h"
#include <math.h>
// The default buffer size, Can't recall the scope of defines right now
#ifndef TWI_RX_BUFFER_SIZE
#define TWI_RX_BUFFER_SIZE ( 16 )
#endif

bool recievedCount = false; //Bool for byte count receieved
int bitmessagesize; //Bit count of message
int messagesize; //Byte count of message.
int messagearray[4]; //Byte array
int bytecount = 0; //How many bytes recieved
int finalmessage;

void setup() {
  TinyWireS.begin(2);
  mySwitch.enableTransmit(3);
}
//Recieve Wire Messages
//1. How many bits (calculate how many bytes to recieve)
//2. Bytes[0]...Bytes[N]. - Note on final byte the end non used bits must be 0
//3. Iterations
//Put together final message.
//Send via RF.
void loop() {
  //Do not use delay() use tws_delay()
  if(TinyWireS.available()){
    //Check if ByteCount has been recieved
    if(recievedCount == false){
      bitmessagesize = TinyWireS.receive();
      float howmanybytes = bitmessagesize / 8;
      messagesize = round(howmanybytes);
      recievedCount = true;
    }
    else if(recievedCount == true){
      //Recieve Bytes
      if(messagesize > bytecount){
        messagearray[bytecount] = TinyWireS.receive();
        bytecount++;
      }
      //Create final message and transmit
      else{
        recievedCount = false;
        //Create final message
        for(int x=0;x<=messagesize;x++){
          finalmessage = messagearray[x] << ((messagesize * 8) - x);
        }
        int shiftdown = ((messagesize * 8) - bitmessagesize);
        finalmessage >> shiftdown;
        //USE FINAL MESSAGE OFC
      }
    }
  }
}


Uno Code
Code: [Select]
//#include <Wire.h>
#include <stdio.h>
#include <math.h>
//#include <iostream>
//#include <cstring>

void transmitmessage(char* message);

void setup() {
  // put your setup code here, to run once:
 Wire.begin();
 Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:

  transmitmessage("001100110011");
}

void transmitmessage(char* message) {
 
  int bits = strlen(message);
  int bytes = round(bits / 8);
  int bytecount = 0;
  int bytearray[5];
  for (int x = 0; x <= bytes; x++) {
    for (int y = 0; y <= 8; y++) {
      if ((8 * x) > bits) {
        bytearray[x] |= 0 << y;
      }
      else {
        if (message[y + (8 * x)] == '0') {
          bytearray[x] |= 0 << y;
        }
        if (message[y + (8 * x)] == '1') {
          bytearray[x] |= 1 << y;

        }
      }
    }
  }
  Wire.beginTransmission(2);
  Wire.write(bits);
  Wire.endTransmission();
  for (int z = 0; z <= bytes; z++) {
   Wire.beginTransmission(2);
   Wire.write(bytearray[z]);
   Wire.endTransmission();
    // Serial.println(bytearray[z]);
  }
 
}


As I said I do apologise since this is my first time trying to use I2C and on the ATTiny its just getting my head around it.

The library used for ATTiny45 is https://github.com/rambo/TinyWire
4
Generale / Re: Collegamento Mega - relay ...
Last post by fenestren - Today at 05:54 pm
Quindi il Mega al piano sotto pilota l'ingresso dell'opto mentre l'uscita dell'opto passa nel corrugato e sale in soffitta con un cavo tipo quello per citofoni?

Grazie.
5
Arduino Due / Re: Any tutorial on Due PWM in...
Last post by ard_newbie - Today at 05:54 pm

Yes it works. remember, once you set:
pinMode(LED_BUILTIN, OUTPUT) , you power PIOB (LED_BUILTIN is PB27) and you enable output on that pin, BUT you can always read the status of a pin, since you have powered PIOB.

The sketch works nicely on my DUE.

6
Project Guidance / Re: How to build a steering wh...
Last post by caolandix - Today at 05:54 pm
Hi,
This might help;

http://archive.siliconchip.com.au/cms/A_112519/article.html

http://archive.siliconchip.com.au/cms/A_112550/article.html

It is an indication of one approach, realizing the corrosive environment.

google;            arduino rudder position  schematic

https://signalkool.com/2016/03/part-1-arduino-rudder-reference-led-gauge-for-raymarine/

https://www.youtube.com/watch?v=cUfUsSDFDyE

Or search for this in YouTube;     rudder position indicator arduino

Tom... :)
Great thanks Tom!
7
Project Guidance / issues with a prodject
Last post by rcor78 - Today at 05:53 pm
I am new to the Arduino and programming in general and there is a lot I don understand.
The program I am working on I need to use an if statement and either a for, while or do... while statement. I am trying to use a button to turn a circuit on while turning the running circuits of. the code as I have it so far is attached any help would be greatly appreciated.


int srs = 13;        // name series circuit
int prll = 12;       // name parallel circuit
int btn = 10;        // name the button
int btnst = 0;       // button state (still not sure what this does)
int cnt = 0;         // initailize count
int bk = 1000;       // delay 1 second
void setup() {
  // put your setup code here, to run once:
 pinMode (srs, OUTPUT);    //set series to output
 pinMode (prll, OUTPUT);   // set parallel to output
 pinMode (btn, INPUT);     // set button to input
 digitalWrite (btn, LOW);  // start button in off position
 Serial.begin (9600);
 }
void loop() {
  btnst = digitalRead (btn);
 while (btn == HIGH){        //while the button is pressed turun
  digitalWrite (srs, LOW);   //the other circuits off
  digitalWrite (prll, LOW);
   }
 do {
  if (cnt < 3){
  Serial.println ("a");
 digitalWrite (srs, HIGH);    //blink alternativley both circuits
 digitalWrite (prll, LOW);    //3 three time for 1 second
  delay (bk);
 digitalWrite (srs, LOW);
 digitalWrite (prll, HIGH);
  delay (bk);
      cnt++;
  }else if (cnt < 6){
  Serial.println ("b");
 digitalWrite (srs, HIGH);     // blink alternativley both circuits
 digitalWrite (prll, LOW);     // 3 times for 1/2 a second
  delay (bk/2);
 digitalWrite (srs, LOW);
 digitalWrite (prll, HIGH);
  delay (bk/2);
      cnt++;
  }else if (cnt < 9){
  Serial.println ("c");
 digitalWrite (srs, HIGH);    // blink alternativley both circuits
 digitalWrite (prll, LOW);    // 3 times for 1/4 a second
  delay (bk/4);
 digitalWrite (srs, LOW);
 digitalWrite (prll, HIGH);
  delay (bk/4);
      cnt++;
  }else if (cnt < 15){
  Serial.println ("d");
 digitalWrite (srs, HIGH);     // blink alternativley both circuits
 digitalWrite (prll, LOW);     // 6 times for 1/8 a second
 delay (bk/8);
 digitalWrite (srs, LOW);
 digitalWrite (prll, HIGH);
  delay (bk/8);
      cnt++;
 }else cnt=0;
 Serial.println("e");
 }while (btn == LOW);         // while button is off
}
8
Deutsch / Re: Serielle Kommunikation zwi...
Last post by BJDK - Today at 05:52 pm
Das ist jetzt sehr peinlich ... Entschuldigung
#include <Wire.h>

const int SLAVE_ADR = 2;

union data_u
{
  struct
  {
  uint16_t Dwert;
  uint16_t Zwert;
  uint16_t Mwert;
  uint16_t Rwert;
  uint16_t Kwert;
  };
  byte bytes[10];
};

data_u data;

void setup()
{
 Serial.begin(9600);
  Serial.println("Master");
  Wire.begin(D1,D2);
}

void loop()
{
  getData();
  delay(1000);
}

void getData()
{
  Wire.requestFrom(SLAVE_ADR, sizeof(data));
  for (unsigned int i = 0; i < sizeof(data); i++)
  data.bytes = Wire.read();

  Serial.println(data.Dwert);
  Serial.println(data.Zwert);
  Serial.println(data.Mwert);
  Serial.println(data.Rwert);
  Serial.println(data.Kwert);
}
9
https://www.picz.in.th/image/Y57Ii8

It always return 1149.
Is it broken , is there anyway to fix it

this is my code
https://pastebin.com/cfZrE208
10
Much further. One step at a time. Now that you have a pair of working boards, use those connected write a sketch that does EXACTLY the same thing as the test that worked above. Do not include or use the RS-485 library or serial communication.
Pages: [1] 2 3 ... 10