I2C: UNO Master, Micro Slave & servo trouble.

Hey, guys. ZZ Cat here. =^/.^=

So, I've got this idea where I'm usin' my UNO to read values off a pot, send that to my Micro down the I2C bus & the Micro converts that value to a signal pulse to an attached servo.

So! Problem: Twitching.
I've checked the serial monitor & it's only goin' from 0 to 44 & looping through that, despite the figure being mapped from 0-1023 to 0-179.

The first code document is the master transmitter that I've written up for my Arduino UNO:

/*
                        \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
                        ////////////////////////////////////////\/
                        /\ Arduino I2C Servo Controller(Master) \/
                        /\                v1.0.0                \/
                        /\                                      \/
                        /\             Designed by:             \/
                        /\    Cudby Æronautics International    \/
                        /\////////////////////////////////////////
                        /\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Description:
  This is an I2C serial-based servo controller using the Arduino's UNO & Micro. The UNO is configured as a Master/Writer & the Micro configured as a Slave/Receiver.
  The UNO converts analog values of an attached pot to a serial value & transmits that value to the Micro. The Micro then converts that received serial value to a PWM signal
  to turn the servo according to the position of the potentiometer that's attached to the UNO.

The Circuit:
  UNO:
    > Is either powered by the USB lead or the VIN jack.
    > Leg 1 of the pot is connected to A0 & is pulled high.
    > Leg 2 of the pot is connected to A1 & analog values are read from this pin.
    > Leg 3 of the pot is connected to A2 & is pulled low.
    > A4 (UNO) is connected to D2 (Micro) with a 4k7 pull-up resistor on the SDA bus line.
    > A5 (UNO) is connected to D3 (Micro) with a 4k7 pull-up resistor on the SCL bus line.
  Micro:
    > Is powered by the USB lead.
    > D2 (Micro) is connected to A4 (UNO).
    > D3 (Micro) is connected to A5 (UNO.
    > D4 is connected to the SIG lead of the servo.
    > The + lead of the servo is connected to the 5V pin.
    > The - lead of the servo is connected to the GND pin.
*/

// Libraries:
#include <Wire.h>                                              // Add the use of the I2C library. #hashtagsaregay

// Digital I/O Pins:
const int potHighPin = A0;                                     // Leg 1 of the pot is connected to ADC0.
const int potLowPin = A2;                                      // Leg 3 of the pot is connected to ADC2.

// ADC Pin:
const int potWiperPin = A1;                                    // Leg 2 of the pot is connected to ADC1.

void setup() {
  Serial.begin(9600);                                          // Start the Serial Monitor at 9600BAUD.
  Wire.begin();                                                // Start the I2C Bus. Address is not needed for the master device.
  
  // Pot Properties:
  pinMode(potHighPin, OUTPUT);                                 // Configure Leg 1 of the pot as an output.
  pinMode(potLowPin, OUTPUT);                                  // Configure Leg 3 of the pot as an output.
  digitalWrite(potHighPin, HIGH);                              // Drive Leg 1 of the pot high.
  digitalWrite(potLowPin, LOW);                                // Drive Leg 3 of the pot low.
}

void loop() {
  byte swep = analogRead(potWiperPin);                         // Read the wiper position as an analog value.
  Wire.beginTransmission(4);                                   // Transmit to device #4.
  Wire.write(swep);                                            // Send four bytes.
  Wire.endTransmission();                                      // Stop Transmitting.
}

The second code document is the slave receiver that I've written up for my Arduino Micro:

/*
                        \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
                        ////////////////////////////////////////\/
                        /\ Arduino I2C Servo Controller (Slave) \/
                        /\                v1.0.0                \/
                        /\                                      \/
                        /\             Designed by:             \/
                        /\    Cudby Æronautics International    \/
                        /\////////////////////////////////////////
                        /\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Description:
  This is an I2C serial-based servo controller using the Arduino's UNO & Micro. The UNO is configured as a Master/Writer & the Micro configured as a Slave/Receiver.
  The UNO converts analog values of an attached pot to a serial value & transmits that value to the Micro. The Micro then converts that received serial value to a PWM signal
  to turn the servo according to the position of the potentiometer that's attached to the UNO.

The Circuit:
  UNO:
    > Is either powered by the USB lead or the VIN jack.
    > Leg 1 of the pot is connected to A0 & is pulled high.
    > Leg 2 of the pot is connected to A1 & analog values are read from this pin.
    > Leg 3 of the pot is connected to A2 & is pulled low.
    > A4 (UNO) is connected to D2 (Micro) with a 4k7 pull-up resistor on the SDA bus line.
    > A5 (UNO) is connected to D3 (Micro) with a 4k7 pull-up resistor on the SCL bus line.
  Micro:
    > Is powered by the USB lead.
    > D2 (Micro) is connected to A4 (UNO).
    > D3 (Micro) is connected to A5 (UNO.
    > D4 is connected to the SIG lead of the servo.
    > The + lead of the servo is connected to the 5V pin.
    > The - lead of the servo is connected to the GND pin.
*/

// Libraries:
#include <Servo.h>                                             // Add the use of the Servo library.
#include <Wire.h>                                              // Add the use of the I2C library. #hashtagsaregay

// Servos:
Servo Not_a_servo;                                             // Create a servo called "Not a servo."

void setup() {
  Serial.begin(9600);                                          // Start the Serial Monitor at 9600BAUD.
  Wire.begin(4);                                               // Start the I2C Bus as device #4.
  Wire.onReceive(receiveEvent);                                // Register event.
  
  Not_a_servo.attach(4);                                       // Attach the SIG lead to D4.
}

void loop() {
  
}

void receiveEvent(int Range) {
  if (Wire.available()) {                                      // If there's data available at the I2C port...
    int swep = Wire.read();                                    // Read the received data as an integer.
    swep = map(swep, 0, 1023, 0, 180);                         // map the recieved data to the sweep range.
    Not_a_servo.write(swep);                                   // Turn the servo horn according to the recieved data.
    Serial.println(swep);                                      // Transmit the sweep angle to the serial monitor.
  }
}

First screenie is the bottom end. IE when the pot is at it's lowest point:

Second screenie is the "top end" when I turn the pot about 1/8 of the way up:

Third & final screenie: Here's what happens if I turn the pot higher up...

So, that's what I suspect is causing the twitching. My question to you is... what can I do to fix this?

What are the "screenie"s?

Why isn't this an int?
byte swep = analogRead(potWiperPin); // Read the wiper position as an analog value.

How does this send 4 bytes?
Wire.write(swep); // Send four bytes.

swep is only one byte

On the receive side
swep = map(swep, 0, 1023, 0, 180); // map the recieved data to the sweep range.

How can 1023 come in when you said swep was a byte (0-255) in the original read?

I'm new to using the Arduino's serial features, so go easy on me if I sound a little idiotic.

So, I've changed the line "byte swep = analogRead(potWiperPin);" to "int swep = analogRead(potWiperPin);" like you've said.

I'm not sure, I guessed that it would be sending four bytes because the analog values from the pot is from 0 to 1023, so I assumed it was four.

I think that one goes against your first question because I've now changed that line to an integer, but I still have the same twitching problem. I've also tried shortening the range from 0-1023 to 0-255 & that servo just went wild.

Nevermind. I've solved the problem. Thanks for nothing. I'm gonna carry on this project by myself like I originally intended.

ZZ_Cat, you sound a little disappointed.
There are a few things I want to say about your sketch. I'm afraid you code is working now, but soon you run into other problems.

A byte can be 0...255, so if you want to transmit the analog value of 0...1023, then you need an integer, which is two bytes.
It is easier to start with one byte.

In the Master the loop() runs without delay. Please add a delay to slow it down a little. Perhaps 20ms or 100ms.

In the Slave you might run into trouble by using the Servo and Serial functions. It is better to write the data to a variable and use that variable in the loop().

An Arduino has not enough power for a Servo motor. As soon as the servo motor starts rotating, the Arduino might not work anymore, it might reset, or do other strange things.